Message ID | 20180717005556.29758-2-ying.huang@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 07/16/2018 05:55 PM, Huang, Ying wrote: > +/* > + * For non-HDD swap devices, the fine grained cluster lock is used to > + * protect si->swap_map. But cluster and cluster locks isn't > + * available for HDD, so coarse grained si->lock will be used instead > + * for that. > + */ > static inline struct swap_cluster_info *lock_cluster_or_swap_info( > struct swap_info_struct *si, > unsigned long offset) This nomenclature is not consistent with the rest of the file. We call a "non-HDD" device an "ssd" absolutely everywhere else in the file. Why are you calling it a non-HDD here? (fwiw, HDD _barely_ hits my acronym cache anyway). How about this? /* * Determine the locking method in use for this device. Return * swap_cluster_info if SSD-style cluster-based locking is in place. */ static inline struct swap_cluster_info *lock_cluster_or_swap_info( struct swap_info_struct *si, unsigned long offset) { struct swap_cluster_info *ci; /* Try to use fine-grained SSD-style locking if available: */ ci = lock_cluster(si, offset); /* Otherwise, fall back to traditional, coarse locking: */ if (!ci) spin_lock(&si->lock); return ci; } Which reminds me? Why do we even bother having two locking models?
Dave Hansen <dave.hansen@linux.intel.com> writes: > On 07/16/2018 05:55 PM, Huang, Ying wrote: >> +/* >> + * For non-HDD swap devices, the fine grained cluster lock is used to >> + * protect si->swap_map. But cluster and cluster locks isn't >> + * available for HDD, so coarse grained si->lock will be used instead >> + * for that. >> + */ >> static inline struct swap_cluster_info *lock_cluster_or_swap_info( >> struct swap_info_struct *si, >> unsigned long offset) > > This nomenclature is not consistent with the rest of the file. We call > a "non-HDD" device an "ssd" absolutely everywhere else in the file. Why > are you calling it a non-HDD here? (fwiw, HDD _barely_ hits my acronym > cache anyway). > > How about this? > > /* > * Determine the locking method in use for this device. Return > * swap_cluster_info if SSD-style cluster-based locking is in place. > */ > static inline struct swap_cluster_info *lock_cluster_or_swap_info( > struct swap_info_struct *si, > unsigned long offset) > { > struct swap_cluster_info *ci; > > /* Try to use fine-grained SSD-style locking if available: */ > ci = lock_cluster(si, offset); > > /* Otherwise, fall back to traditional, coarse locking: */ > if (!ci) > spin_lock(&si->lock); > > return ci; > } This is better than my one, will use this. Thanks! > Which reminds me? Why do we even bother having two locking models? Because si->cluster_info is NULL for non-SSD, so we cannot use cluster lock. About why not use struct swap_cluster_info for non-SSD? Per my understanding, struct swap_cluster_info is optimized for SSD. Especially it assumes seeking is cheap. So different free swap slot scanning policy is used for SSD and non-SSD. Best Regards, Huang, Ying
diff --git a/mm/swapfile.c b/mm/swapfile.c index d8fddfb000ec..0a2a9643dd78 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -297,6 +297,12 @@ static inline void unlock_cluster(struct swap_cluster_info *ci) spin_unlock(&ci->lock); } +/* + * For non-HDD swap devices, the fine grained cluster lock is used to + * protect si->swap_map. But cluster and cluster locks isn't + * available for HDD, so coarse grained si->lock will be used instead + * for that. + */ static inline struct swap_cluster_info *lock_cluster_or_swap_info( struct swap_info_struct *si, unsigned long offset)
To improve the code readability. Signed-off-by: "Huang, Ying" <ying.huang@intel.com> Suggested-by: Dave Hansen <dave.hansen@linux.intel.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Shaohua Li <shli@kernel.org> Cc: Hugh Dickins <hughd@google.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Rik van Riel <riel@redhat.com> Cc: Daniel Jordan <daniel.m.jordan@oracle.com> Cc: Dan Williams <dan.j.williams@intel.com> --- mm/swapfile.c | 6 ++++++ 1 file changed, 6 insertions(+)