Skip to content

Commit 65dd2d6

Browse files
committed
afs: Alter dirty range encoding in page->private
Currently, page->private on an afs page is used to store the range of dirtied data within the page, where the range includes the lower bound, but excludes the upper bound (e.g. 0-1 is a range covering a single byte). This, however, requires a superfluous bit for the last-byte bound so that on a 4KiB page, it can say 0-4096 to indicate the whole page, the idea being that having both numbers the same would indicate an empty range. This is unnecessary as the PG_private bit is clear if it's an empty range (as is PG_dirty). Alter the way the dirty range is encoded in page->private such that the upper bound is reduced by 1 (e.g. 0-0 is then specified the same single byte range mentioned above). Applying this to both bounds frees up two bits, one of which can be used in a future commit. This allows the afs filesystem to be compiled on ppc32 with 64K pages; without this, the following warnings are seen: ../fs/afs/internal.h: In function 'afs_page_dirty_to': ../fs/afs/internal.h:881:15: warning: right shift count >= width of type [-Wshift-count-overflow] 881 | return (priv >> __AFS_PAGE_PRIV_SHIFT) & __AFS_PAGE_PRIV_MASK; | ^~ ../fs/afs/internal.h: In function 'afs_page_dirty': ../fs/afs/internal.h:886:28: warning: left shift count >= width of type [-Wshift-count-overflow] 886 | return ((unsigned long)to << __AFS_PAGE_PRIV_SHIFT) | from; | ^~ Fixes: 4343d00 ("afs: Get rid of the afs_writeback record") Signed-off-by: David Howells <[email protected]>
1 parent 185f0c7 commit 65dd2d6

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

fs/afs/internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ struct afs_vnode_cache_aux {
863863
* splitting the field into two parts. However, we need to represent a range
864864
* 0...PAGE_SIZE inclusive, so we can't support 64K pages on a 32-bit system.
865865
*/
866-
#if PAGE_SIZE > 32768
866+
#ifdef CONFIG_64BIT
867867
#define __AFS_PAGE_PRIV_MASK 0xffffffffUL
868868
#define __AFS_PAGE_PRIV_SHIFT 32
869869
#else
@@ -878,12 +878,12 @@ static inline size_t afs_page_dirty_from(unsigned long priv)
878878

879879
static inline size_t afs_page_dirty_to(unsigned long priv)
880880
{
881-
return (priv >> __AFS_PAGE_PRIV_SHIFT) & __AFS_PAGE_PRIV_MASK;
881+
return ((priv >> __AFS_PAGE_PRIV_SHIFT) & __AFS_PAGE_PRIV_MASK) + 1;
882882
}
883883

884884
static inline unsigned long afs_page_dirty(size_t from, size_t to)
885885
{
886-
return ((unsigned long)to << __AFS_PAGE_PRIV_SHIFT) | from;
886+
return ((unsigned long)(to - 1) << __AFS_PAGE_PRIV_SHIFT) | from;
887887
}
888888

889889
#include <trace/events/afs.h>

fs/afs/write.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ int afs_write_begin(struct file *file, struct address_space *mapping,
9393
/* We want to store information about how much of a page is altered in
9494
* page->private.
9595
*/
96-
BUILD_BUG_ON(PAGE_SIZE > 32768 && sizeof(page->private) < 8);
96+
BUILD_BUG_ON(PAGE_SIZE - 1 > __AFS_PAGE_PRIV_MASK && sizeof(page->private) < 8);
9797

9898
page = grab_cache_page_write_begin(mapping, index, flags);
9999
if (!page)

0 commit comments

Comments
 (0)