mm, swap: Fix false error message in __swp_swapcount()
Subsystems (3)
PATCH 1/1 mm, swap: Fix false error message in __swp_swapcount()
From: Ying Huang <[email protected]>
__swp_swapcount() is used in __read_swap_cache_async(). Where the invalid swap entry (offset > max) may be supplied during swap readahead. But __swp_swapcount() will print error message for these expected invalid swap entry as below, which will make the users confusing.
swap_info_get: Bad swap offset entry 0200f8a7
So the swap entry checking code in __swp_swapcount() is changed to avoid printing error message for it. To avoid to duplicate code with __swap_duplicate(), a new helper function named __swap_info_get_silence() is added and invoked in both places.
--- mm/swapfile.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-)
mm/swapfile.c +28 -14
@@ -1107,6 +1107,30 @@ static struct swap_info_struct *swap_info_get_cont(swp_entry_t entry,return p; } +static struct swap_info_struct *__swap_info_get_silence (swp_entry_t entry) +{ +struct swap_info_struct *p; +unsigned long offset, type; + +if (non_swap_entry (entry)) + goto out; + + type =swp_type (entry); +if (type >= nr_swapfiles) + goto bad_file; + p = swap_info[type]; + offset =swp_offset (entry); +if (unlikely (offset >= p->max)) + goto out; + +return p; + +bad_file: +pr_err ("swap_info_get_silence: %s%08lx\n" , Bad_file, entry.val); +out: +return NULL ; +} +static unsigned char __swap_entry_free (struct swap_info_struct *p,swp_entry_t entry,unsigned char usage) {
@@ -1357,7 +1381,7 @@ int __swp_swapcount(swp_entry_t entry)int count =0 ;struct swap_info_struct *si; - si =__swap_info_get (entry); + si =__swap_info_get_silence (entry);if (si) count =swap_swapcount (si, entry);return count;
@@ -3356,22 +3380,16 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage) {struct swap_info_struct *p;struct swap_cluster_info *ci; -unsigned long offset, type; +unsigned long offset;unsigned char count;unsigned char has_cache;int err = -EINVAL ; -if (non_swap_entry (entry)) + p =__swap_info_get_silence (entry); +if (!p) goto out; - type =swp_type (entry); -if (type >= nr_swapfiles) - goto bad_file; - p = swap_info[type]; offset =swp_offset (entry); -if (unlikely (offset >= p->max)) - goto out; - ci =lock_cluster_or_swap_info (p, offset); count = p->swap_map[offset];
@@ -3418,10 +3436,6 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage)unlock_cluster_or_swap_info (p, ci); out:return err; - -bad_file: -pr_err ("swap_dup: %s%08lx\n" , Bad_file, entry.val); - goto out; }/*
Signature · 7 lines
2.14.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · Ying
From: Ying Huang <[email protected]>
__swp_swapcount()is used in__read_swap_cache_async(). Where the invalid swap entry (offset > max) may be supplied during swap readahead. But__swp_swapcount()will print error message for these expected invalid swap entry as below, which will make the users confusing.
^^
confused... And I have to admit this changelog has left me confused as well. What is an invalid swap entry in the readahead? Ohh, let me re-real Fixes: commit. It didn't really help "We can avoid needlessly allocating page for swap slots that are not used by anyone. No pages have to be read in for these slots."
Could you be more specific about when and how this happens please?
Quoted 102 lines
swap_info_get: Bad swap offset entry0200f8a7So the swap entry checking code in
__swp_swapcount()is changed to avoid printing error message for it. To avoid to duplicate code with__swap_duplicate(), a new helper function named__swap_info_get_silence()is added and invoked in both places.Cc Tim Chen <[email protected]>Cc Minchan Kim <[email protected]>Cc Michal Hocko <[email protected]>Cc <[email protected]> # 4.11-4.13Reported-by Christian Kujau <[email protected]>Fixes e8c26ab60598 ("mm/swap: skip readahead for unreferenced swap slots")Signed-off-by "Huang, Ying" <[email protected]>--- mm/swapfile.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-)mm/swapfile.c +28
-14@@ -1107,6 +1107,30 @@ static struct swap_info_struct *swap_info_get_cont(swp_entry_t entry,return p; } +static struct swap_info_struct *__swap_info_get_silence (swp_entry_t entry) +{ +struct swap_info_struct *p; +unsigned long offset, type; + +if (non_swap_entry (entry)) + goto out; + + type =swp_type (entry); +if (type >= nr_swapfiles) + goto bad_file; + p = swap_info[type]; + offset =swp_offset (entry); +if (unlikely (offset >= p->max)) + goto out; + +return p; + +bad_file: +pr_err ("swap_info_get_silence: %s%08lx\n" , Bad_file, entry.val); +out: +return NULL ; +} +static unsigned char __swap_entry_free (struct swap_info_struct *p,swp_entry_t entry,unsigned char usage) {@@ -1357,7 +1381,7 @@ int __swp_swapcount(swp_entry_t entry)int count =0 ;struct swap_info_struct *si; - si =__swap_info_get (entry); + si =__swap_info_get_silence (entry);if (si) count =swap_swapcount (si, entry);return count;@@ -3356,22 +3380,16 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage) {struct swap_info_struct *p;struct swap_cluster_info *ci; -unsigned long offset, type; +unsigned long offset;unsigned char count;unsigned char has_cache;int err = -EINVAL ; -if (non_swap_entry (entry)) + p =__swap_info_get_silence (entry); +if (!p) goto out; - type =swp_type (entry); -if (type >= nr_swapfiles) - goto bad_file; - p = swap_info[type]; offset =swp_offset (entry); -if (unlikely (offset >= p->max)) - goto out; - ci =lock_cluster_or_swap_info (p, offset); count = p->swap_map[offset];@@ -3418,10 +3436,6 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage)unlock_cluster_or_swap_info (p, ci); out:return err; - -bad_file: -pr_err ("swap_dup: %s%08lx\n" , Bad_file, entry.val); - goto out; }/* Signature · 1 line
2.14.2
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi, Michal,
Quoted 8 lines · Michal Hocko
Quoted 7 lines · Ying
From: Ying Huang <[email protected]>
__swp_swapcount()is used in__read_swap_cache_async(). Where the invalid swap entry (offset > max) may be supplied during swap readahead. But__swp_swapcount()will print error message for these expected invalid swap entry as below, which will make the users confusing.
Quoted 8 lines
^^
confused... And I have to admit this changelog has left me confused as well. What is an invalid swap entry in the readahead? Ohh, let me re-real Fixes: commit. It didn't really help "We can avoid needlessly allocating page for swap slots that are not used by anyone. No pages have to be read in for these slots."Could you be more specific about when and how this happens please?
Sorry for confusing.
When page fault occurs for a swap entry, the original swap readahead (not new VMA base swap readahead) may readahead several swap entries after the fault swap entry. The readahead algorithm calculates some of the swap entries to readahead via increasing the offset of the fault swap entry without checking whether they are beyond the end of the swap device and it rely on the __swp_swapcount() and swapcache_prepare() to check it. Although __swp_swapcount() checks for the swap entry passed in, it will complain with error message for the expected invalid swap entry. This makes the end user confusing.
Is this a little clearer.
Best Regards,
Huang, Ying
Quoted 98 lines
Quoted 98 lines
swap_info_get: Bad swap offset entry0200f8a7So the swap entry checking code in
__swp_swapcount()is changed to avoid printing error message for it. To avoid to duplicate code with__swap_duplicate(), a new helper function named__swap_info_get_silence()is added and invoked in both places.Cc Tim Chen <[email protected]>Cc Minchan Kim <[email protected]>Cc Michal Hocko <[email protected]>Cc <[email protected]> # 4.11-4.13Reported-by Christian Kujau <[email protected]>Fixes e8c26ab60598 ("mm/swap: skip readahead for unreferenced swap slots")Signed-off-by "Huang, Ying" <[email protected]>--- mm/swapfile.c | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-)mm/swapfile.c +28
-14@@ -1107,6 +1107,30 @@ static struct swap_info_struct *swap_info_get_cont(swp_entry_t entry,return p; } +static struct swap_info_struct *__swap_info_get_silence (swp_entry_t entry) +{ +struct swap_info_struct *p; +unsigned long offset, type; + +if (non_swap_entry (entry)) + goto out; + + type =swp_type (entry); +if (type >= nr_swapfiles) + goto bad_file; + p = swap_info[type]; + offset =swp_offset (entry); +if (unlikely (offset >= p->max)) + goto out; + +return p; + +bad_file: +pr_err ("swap_info_get_silence: %s%08lx\n" , Bad_file, entry.val); +out: +return NULL ; +} +static unsigned char __swap_entry_free (struct swap_info_struct *p,swp_entry_t entry,unsigned char usage) {@@ -1357,7 +1381,7 @@ int __swp_swapcount(swp_entry_t entry)int count =0 ;struct swap_info_struct *si; - si =__swap_info_get (entry); + si =__swap_info_get_silence (entry);if (si) count =swap_swapcount (si, entry);return count;@@ -3356,22 +3380,16 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage) {struct swap_info_struct *p;struct swap_cluster_info *ci; -unsigned long offset, type; +unsigned long offset;unsigned char count;unsigned char has_cache;int err = -EINVAL ; -if (non_swap_entry (entry)) + p =__swap_info_get_silence (entry); +if (!p) goto out; - type =swp_type (entry); -if (type >= nr_swapfiles) - goto bad_file; - p = swap_info[type]; offset =swp_offset (entry); -if (unlikely (offset >= p->max)) - goto out; - ci =lock_cluster_or_swap_info (p, offset); count = p->swap_map[offset];@@ -3418,10 +3436,6 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage)unlock_cluster_or_swap_info (p, ci); out:return err; - -bad_file: -pr_err ("swap_dup: %s%08lx\n" , Bad_file, entry.val); - goto out; }
Quoted 4 lines
Quoted 4 lines
mm/swapfile.c +0
-0/* Signature · 1 line
2.14.2
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 33 lines · Ying
Hi, Michal,
Quoted 8 lines · Michal Hocko
Quoted 7 lines · Ying
From: Ying Huang <[email protected]>
__swp_swapcount()is used in__read_swap_cache_async(). Where the invalid swap entry (offset > max) may be supplied during swap readahead. But__swp_swapcount()will print error message for these expected invalid swap entry as below, which will make the users confusing.Quoted 8 lines
^^
confused... And I have to admit this changelog has left me confused as well. What is an invalid swap entry in the readahead? Ohh, let me re-real Fixes: commit. It didn't really help "We can avoid needlessly allocating page for swap slots that are not used by anyone. No pages have to be read in for these slots."Could you be more specific about when and how this happens please?
Sorry for confusing.
When page fault occurs for a swap entry, the original swap readahead (not new VMA base swap readahead) may readahead several swap entries after the fault swap entry. The readahead algorithm calculates some of the swap entries to readahead via increasing the offset of the fault swap entry without checking whether they are beyond the end of the swap device and it rely on the
__swp_swapcount()andswapcache_prepare()to check it. Although__swp_swapcount()checks for the swap entry passed in, it will complain with error message for the expected invalid swap entry. This makes the end user confusing.
Quoted 1 line
Is this a little clearer.
yes, this makes more sense (modulo the same typo ;)). Can you make this information into the changelog please? Thanks.
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 34 lines · Michal Hocko
Quoted 33 lines · Ying
Hi, Michal,
Quoted 8 lines · Michal Hocko
Quoted 7 lines · Ying
From: Ying Huang <[email protected]>
__swp_swapcount()is used in__read_swap_cache_async(). Where the invalid swap entry (offset > max) may be supplied during swap readahead. But__swp_swapcount()will print error message for these expected invalid swap entry as below, which will make the users confusing.Quoted 8 lines
^^
confused... And I have to admit this changelog has left me confused as well. What is an invalid swap entry in the readahead? Ohh, let me re-real Fixes: commit. It didn't really help "We can avoid needlessly allocating page for swap slots that are not used by anyone. No pages have to be read in for these slots."Could you be more specific about when and how this happens please?
Sorry for confusing.
When page fault occurs for a swap entry, the original swap readahead (not new VMA base swap readahead) may readahead several swap entries after the fault swap entry. The readahead algorithm calculates some of the swap entries to readahead via increasing the offset of the fault swap entry without checking whether they are beyond the end of the swap device and it rely on the
__swp_swapcount()andswapcache_prepare()to check it. Although__swp_swapcount()checks for the swap entry passed in, it will complain with error message for the expected invalid swap entry. This makes the end user confusing.
Quoted 4 lines
Quoted 1 line
Is this a little clearer.
yes, this makes more sense (modulo the same typo ;)). Can you make this information into the changelog please? Thanks.
Oh, Yes! I should fix it. Sure, I will add this into the changelog.
Best Regards,
Huang, Ying
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · Ying
From: Ying Huang <[email protected]>
__swp_swapcount()is used in__read_swap_cache_async(). Where the invalid swap entry (offset > max) may be supplied during swap readahead. But__swp_swapcount()will print error message for these expected invalid swap entry as below, which will make the users confusing.
Quoted 6 lines
swap_info_get: Bad swap offset entry0200f8a7So the swap entry checking code in
__swp_swapcount()is changed to avoid printing error message for it. To avoid to duplicate code with__swap_duplicate(), a new helper function named__swap_info_get_silence()is added and invoked in both places.
It's the problem caused by readahead, not __swap_info_get which is low-end primitive function. Instead, please fix high-end swapin_readahead to limit to last valid block as handling to avoid swap header which is special case, too.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 16 lines · Minchan Kim
Quoted 8 lines · Ying
From: Ying Huang <[email protected]>
__swp_swapcount()is used in__read_swap_cache_async(). Where the invalid swap entry (offset > max) may be supplied during swap readahead. But__swp_swapcount()will print error message for these expected invalid swap entry as below, which will make the users confusing.Quoted 6 lines
swap_info_get: Bad swap offset entry0200f8a7So the swap entry checking code in
__swp_swapcount()is changed to avoid printing error message for it. To avoid to duplicate code with__swap_duplicate(), a new helper function named__swap_info_get_silence()is added and invoked in both places.
Quoted 4 lines
It's the problem caused by readahead, not
__swap_info_getwhich is low-end primitive function. Instead, please fix high-endswapin_readaheadto limit to last valid block as handling to avoid swap header which is special case, too.
Yes. You are right, will send the new version.
Best Regards,
Huang, Ying
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>