Skip to content

Commit a34847d

Browse files
committed
afs: Don't use folio->private to record partial modification
AFS currently uses folio->private to store the range of bytes within a folio that have been modified - the idea being that if we have, say, a 2MiB folio and someone writes a single byte, we only have to write back that single page and not the whole 2MiB folio - thereby saving on network bandwidth. Remove this, at least for now, and accept the extra network load (which doesn't matter in the common case of writing a whole file at a time from beginning to end). This makes folio->private available for netfslib to use. Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> cc: Marc Dionne <marc.dionne@auristor.com> cc: linux-afs@lists.infradead.org cc: linux-cachefs@redhat.com cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org
1 parent 5f5ce7b commit a34847d

4 files changed

Lines changed: 42 additions & 285 deletions

File tree

fs/afs/file.c

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -386,63 +386,6 @@ const struct netfs_request_ops afs_req_ops = {
386386
.issue_read = afs_issue_read,
387387
};
388388

389-
/*
390-
* Adjust the dirty region of the page on truncation or full invalidation,
391-
* getting rid of the markers altogether if the region is entirely invalidated.
392-
*/
393-
static void afs_invalidate_dirty(struct folio *folio, size_t offset,
394-
size_t length)
395-
{
396-
struct afs_vnode *vnode = AFS_FS_I(folio_inode(folio));
397-
unsigned long priv;
398-
unsigned int f, t, end = offset + length;
399-
400-
priv = (unsigned long)folio_get_private(folio);
401-
402-
/* we clean up only if the entire page is being invalidated */
403-
if (offset == 0 && length == folio_size(folio))
404-
goto full_invalidate;
405-
406-
/* If the page was dirtied by page_mkwrite(), the PTE stays writable
407-
* and we don't get another notification to tell us to expand it
408-
* again.
409-
*/
410-
if (afs_is_folio_dirty_mmapped(priv))
411-
return;
412-
413-
/* We may need to shorten the dirty region */
414-
f = afs_folio_dirty_from(folio, priv);
415-
t = afs_folio_dirty_to(folio, priv);
416-
417-
if (t <= offset || f >= end)
418-
return; /* Doesn't overlap */
419-
420-
if (f < offset && t > end)
421-
return; /* Splits the dirty region - just absorb it */
422-
423-
if (f >= offset && t <= end)
424-
goto undirty;
425-
426-
if (f < offset)
427-
t = offset;
428-
else
429-
f = end;
430-
if (f == t)
431-
goto undirty;
432-
433-
priv = afs_folio_dirty(folio, f, t);
434-
folio_change_private(folio, (void *)priv);
435-
trace_afs_folio_dirty(vnode, tracepoint_string("trunc"), folio);
436-
return;
437-
438-
undirty:
439-
trace_afs_folio_dirty(vnode, tracepoint_string("undirty"), folio);
440-
folio_clear_dirty_for_io(folio);
441-
full_invalidate:
442-
trace_afs_folio_dirty(vnode, tracepoint_string("inval"), folio);
443-
folio_detach_private(folio);
444-
}
445-
446389
/*
447390
* invalidate part or all of a page
448391
* - release a page and clean up its private data if offset is 0 (indicating
@@ -453,11 +396,6 @@ static void afs_invalidate_folio(struct folio *folio, size_t offset,
453396
{
454397
_enter("{%lu},%zu,%zu", folio->index, offset, length);
455398

456-
BUG_ON(!folio_test_locked(folio));
457-
458-
if (folio_get_private(folio))
459-
afs_invalidate_dirty(folio, offset, length);
460-
461399
folio_wait_fscache(folio);
462400
_leave("");
463401
}
@@ -485,11 +423,6 @@ static bool afs_release_folio(struct folio *folio, gfp_t gfp)
485423
fscache_note_page_release(afs_vnode_cache(vnode));
486424
#endif
487425

488-
if (folio_test_private(folio)) {
489-
trace_afs_folio_dirty(vnode, tracepoint_string("rel"), folio);
490-
folio_detach_private(folio);
491-
}
492-
493426
/* Indicate that the folio can be released */
494427
_leave(" = T");
495428
return true;

fs/afs/internal.h

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -894,62 +894,6 @@ static inline void afs_invalidate_cache(struct afs_vnode *vnode, unsigned int fl
894894
i_size_read(&vnode->netfs.inode), flags);
895895
}
896896

897-
/*
898-
* We use folio->private to hold the amount of the folio that we've written to,
899-
* splitting the field into two parts. However, we need to represent a range
900-
* 0...FOLIO_SIZE, so we reduce the resolution if the size of the folio
901-
* exceeds what we can encode.
902-
*/
903-
#ifdef CONFIG_64BIT
904-
#define __AFS_FOLIO_PRIV_MASK 0x7fffffffUL
905-
#define __AFS_FOLIO_PRIV_SHIFT 32
906-
#define __AFS_FOLIO_PRIV_MMAPPED 0x80000000UL
907-
#else
908-
#define __AFS_FOLIO_PRIV_MASK 0x7fffUL
909-
#define __AFS_FOLIO_PRIV_SHIFT 16
910-
#define __AFS_FOLIO_PRIV_MMAPPED 0x8000UL
911-
#endif
912-
913-
static inline unsigned int afs_folio_dirty_resolution(struct folio *folio)
914-
{
915-
int shift = folio_shift(folio) - (__AFS_FOLIO_PRIV_SHIFT - 1);
916-
return (shift > 0) ? shift : 0;
917-
}
918-
919-
static inline size_t afs_folio_dirty_from(struct folio *folio, unsigned long priv)
920-
{
921-
unsigned long x = priv & __AFS_FOLIO_PRIV_MASK;
922-
923-
/* The lower bound is inclusive */
924-
return x << afs_folio_dirty_resolution(folio);
925-
}
926-
927-
static inline size_t afs_folio_dirty_to(struct folio *folio, unsigned long priv)
928-
{
929-
unsigned long x = (priv >> __AFS_FOLIO_PRIV_SHIFT) & __AFS_FOLIO_PRIV_MASK;
930-
931-
/* The upper bound is immediately beyond the region */
932-
return (x + 1) << afs_folio_dirty_resolution(folio);
933-
}
934-
935-
static inline unsigned long afs_folio_dirty(struct folio *folio, size_t from, size_t to)
936-
{
937-
unsigned int res = afs_folio_dirty_resolution(folio);
938-
from >>= res;
939-
to = (to - 1) >> res;
940-
return (to << __AFS_FOLIO_PRIV_SHIFT) | from;
941-
}
942-
943-
static inline unsigned long afs_folio_dirty_mmapped(unsigned long priv)
944-
{
945-
return priv | __AFS_FOLIO_PRIV_MMAPPED;
946-
}
947-
948-
static inline bool afs_is_folio_dirty_mmapped(unsigned long priv)
949-
{
950-
return priv & __AFS_FOLIO_PRIV_MMAPPED;
951-
}
952-
953897
#include <trace/events/afs.h>
954898

955899
/*****************************************************************************/

0 commit comments

Comments
 (0)