[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aHdQO/SN9MUL5/Bk@MiWiFi-R3L-srv>
Date: Wed, 16 Jul 2025 15:09:47 +0800
From: Baoquan He <bhe@...hat.com>
To: Kairui Song <kasong@...cent.com>
Cc: linux-mm@...ck.org, Andrew Morton <akpm@...ux-foundation.org>,
Hugh Dickins <hughd@...gle.com>,
Baolin Wang <baolin.wang@...ux.alibaba.com>,
Matthew Wilcox <willy@...radead.org>,
Kemeng Shi <shikemeng@...weicloud.com>,
Chris Li <chrisl@...nel.org>, Nhat Pham <nphamcs@...il.com>,
Barry Song <baohua@...nel.org>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v5 4/8] mm/shmem, swap: tidy up swap entry splitting
On 07/10/25 at 11:37am, Kairui Song wrote:
......snip...
> @@ -2321,46 +2323,35 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
> }
>
> /*
> - * Now swap device can only swap in order 0 folio, then we
> - * should split the large swap entry stored in the pagecache
> - * if necessary.
> - */
> - split_order = shmem_split_large_entry(inode, index, swap, gfp);
> - if (split_order < 0) {
> - error = split_order;
> - goto failed;
> - }
> -
> - /*
> - * If the large swap entry has already been split, it is
> + * Now swap device can only swap in order 0 folio, it is
> * necessary to recalculate the new swap entry based on
> - * the old order alignment.
> + * the offset, as the swapin index might be unalgined.
> */
> - if (split_order > 0) {
> - pgoff_t offset = index - round_down(index, 1 << split_order);
> -
> + if (order) {
> + offset = index - round_down(index, 1 << order);
> swap = swp_entry(swp_type(swap), swp_offset(swap) + offset);
> }
>
> - /* Here we actually start the io */
> folio = shmem_swapin_cluster(swap, gfp, info, index);
> if (!folio) {
> error = -ENOMEM;
> goto failed;
> }
> - } else if (order > folio_order(folio)) {
> + }
> +alloced:
Here, only synchronous device handling will jump to label 'alloced', while
its folio is allocated with order. Maybe we should move the label down
below these if else conditional checking and handling?
Anyway, this is an intermediary patch and code will be changed, not strong
opinion.
> + if (order > folio_order(folio)) {
> /*
> - * Swap readahead may swap in order 0 folios into swapcache
> + * Swapin may get smaller folios due to various reasons:
> + * It may fallback to order 0 due to memory pressure or race,
> + * swap readahead may swap in order 0 folios into swapcache
> * asynchronously, while the shmem mapping can still stores
> * large swap entries. In such cases, we should split the
> * large swap entry to prevent possible data corruption.
> */
> - split_order = shmem_split_large_entry(inode, index, swap, gfp);
> + split_order = shmem_split_large_entry(inode, index, index_entry, gfp);
> if (split_order < 0) {
> - folio_put(folio);
> - folio = NULL;
> error = split_order;
> - goto failed;
> + goto failed_nolock;
> }
>
> /*
...snip...
Powered by blists - more mailing lists