]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: fadvise: move 'endbyte' calculations to helper function
authorCharan Teja Kalla <quic_charante@quicinc.com>
Tue, 14 Feb 2023 12:51:49 +0000 (18:21 +0530)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 5 Apr 2023 23:02:05 +0000 (16:02 -0700)
Patch series "mm: shmem: support POSIX_FADV_[WILL|DONT]NEED for shmem
files", v7.

This patchset aims to implement POSIX_FADV_WILLNEED and
POSIX_FADV_DONTNEED advices to shmem files which can be helpful for the
drivers who may want to manage the pages of shmem files on their own,
like, that are created through shmem_file_setup[_with_mnt]().

This patch (of 2):

Move the 'endbyte' calculations that determines last byte that fadvise can
to a helper function.  This is a preparatory change made for
shmem_fadvise() functionality in the next patch.  No functional changes in
this patch.

Link: https://lkml.kernel.org/r/cover.1676378702.git.quic_charante@quicinc.com
Link: https://lkml.kernel.org/r/22de7e716051abbafc01fab9f479f4d5b03745ca.1676378702.git.quic_charante@quicinc.com
Signed-off-by: Charan Teja Kalla <quic_charante@quicinc.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Mark Hemment <markhemm@googlemail.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Pavankumar Kondeti <quic_pkondeti@quicinc.com>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/fadvise.c
mm/internal.h

index fb7c5f43fd2a65730e0d1a8d44b568e3580f17b3..1b3cac58735ce729577dd5e64c2adb08ce278b7d 100644 (file)
@@ -65,16 +65,7 @@ int generic_fadvise(struct file *file, loff_t offset, loff_t len, int advice)
                return 0;
        }
 
-       /*
-        * Careful about overflows. Len == 0 means "as much as possible".  Use
-        * unsigned math because signed overflows are undefined and UBSan
-        * complains.
-        */
-       endbyte = (u64)offset + (u64)len;
-       if (!len || endbyte < len)
-               endbyte = LLONG_MAX;
-       else
-               endbyte--;              /* inclusive */
+       endbyte = fadvise_calc_endbyte(offset, len);
 
        switch (advice) {
        case POSIX_FADV_NORMAL:
index 2a7ffd9962c43aec418ed672c80b68013a1af0b3..08ce56dbb1d997c01ce38d1606c4176ac04db25a 100644 (file)
@@ -657,6 +657,27 @@ static inline void vunmap_range_noflush(unsigned long start, unsigned long end)
 }
 #endif /* !CONFIG_MMU */
 
+/*
+ * Helper function to get the endbyte of a file that fadvise can operate on.
+ */
+static inline loff_t fadvise_calc_endbyte(loff_t offset, loff_t len)
+{
+       loff_t endbyte;
+
+       /*
+        * Careful about overflows. Len == 0 means "as much as possible".  Use
+        * unsigned math because signed overflows are undefined and UBSan
+        * complains.
+        */
+       endbyte = (u64)offset + (u64)len;
+       if (!len || endbyte < len)
+               endbyte = LLONG_MAX;
+       else
+               endbyte--;              /* inclusive */
+
+       return endbyte;
+}
+
 /* Memory initialisation debug and verification */
 enum mminit_level {
        MMINIT_WARNING,