From nobody Wed Feb 11 05:04:55 2026 Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90BA51D7E21 for ; Fri, 7 Feb 2025 09:44:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.97 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921481; cv=none; b=RfrSU8fDDQuuQPf2RZskGALFnCnhXRwGdAqg6062po+m9lzT8j9FVRi0DpwiEZ9czkuZykMhBgiAKdS4HjSqHgQrcN/4kaR3Bi0tvV97QyGd5/HQGQFQfZka8m9hMljBvZC8jzDDC/nrYpHvWwVWJIo6iu7WM8NGZGRsI/uhgok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921481; c=relaxed/simple; bh=pAzvpUcHqz6pHDmg7cp1GbIvS5Li6GN0WDVBgMBizMc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ntD9+4UKufFV9V565TDxnZqWUuNR6Hvq8YmEKlyf8ZnLS/dHa226tMc4wHeCyAgkHJ/9hK54PSG55MWtIe0PVnqljnppobKBqEO5PkNmRvd8F8iOv+FIE2wciVOJ0w9MfMhNdnU2lvVPlz/VG6DsqmlM1UTH4wXN8D4yCQiKsds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=ee+lIRoX; arc=none smtp.client-ip=115.124.30.97 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="ee+lIRoX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1738921469; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=6OliDxvKyBEcspL0hO2n4TFk9yLu1eglYM5udcyOR2M=; b=ee+lIRoXoS4qpTr8aJvnSxk9jH0gPQUA97N8vCdA998XHQL7qJaaOXxyZaJYOc4rrr0oKETF2A+ySDvDJttsDna+bzqAMEaNpDm4HwLhfSbp9GNghSL8jsWNlUi5t8fGf/YtFb3FyAX3TjWWkuHl3yK35u3KPTpUfmNormu1daQ= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WOz4ojL_1738921468 cluster:ay36) by smtp.aliyun-inc.com; Fri, 07 Feb 2025 17:44:29 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: david@redhat.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/6] mm: shmem: drop the unused macro Date: Fri, 7 Feb 2025 17:44:17 +0800 Message-Id: <69264cee1d938442477e657004e4924f8a5c4dd4.1738918357.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Drop the unused 'BLOCKS_PER_PAGE' macro. Signed-off-by: Baolin Wang --- mm/shmem.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index 745f130bfb4c..ddf800357e7a 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -86,7 +86,6 @@ static struct vfsmount *shm_mnt __ro_after_init; =20 #include "internal.h" =20 -#define BLOCKS_PER_PAGE (PAGE_SIZE/512) #define VM_ACCT(size) (PAGE_ALIGN(size) >> PAGE_SHIFT) =20 /* Pretend that each entry is of this size in directory's i_size */ --=20 2.39.3 From nobody Wed Feb 11 05:04:55 2026 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20E951DE3B1 for ; Fri, 7 Feb 2025 09:44:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921481; cv=none; b=QXaFPcmZN3Euh5GSHq2Qwd0P0oIRPh76XznC2kh6A71HOCwFceJwFoqnsvm9aSvxP/T12xMlP6ucUpbU8XzcOKIeJrSgqkJBMvT5EMAHpSACeOsyQ70X9l1N2Lf8YZx3+MJn5u/4f3guRpHvNvXrkSuYmkSLLggGiUXnnx4wELc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921481; c=relaxed/simple; bh=sS5JxqZg5kTZup42wGhqtzc0oextva1bVrjA5BrW9Bo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pzh5wmPvnAiml+fSr9NlOKJeMg9+kWEOpf5ONyjgxAGNhE0ghFX9jDTAbhMqtZ8f12aCYKKQH4v0hrvbK9EQI8NublNz1zCIkotNhdgNpA6HthVsMzswOPXL5JCnQw2G2K7RiTFaKEvixa9g3qlp9M0jqzNqZr5HnBBP5K4Nfq0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=F53DoYrb; arc=none smtp.client-ip=115.124.30.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="F53DoYrb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1738921470; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=fDtKOoTlfOTw82XR7J+JbdVd7+T6vjeWrc6ajVUoZGA=; b=F53DoYrbzEM6WJ2hvRHp/AOUl/w/O8pWeuDEk8PwJ0jjQpu4lStOevA8KL2oAydD4iucUzihkioQ28ngjf0zqKJeKr2Jf3OkGwXjMIrLeLR2qfpX+S/O9WnNWpOiqqc/LXW5GQqN08LEd+9v/b9JJJk717dKQcHxGINPlzGDkdE= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WOz4ojg_1738921469 cluster:ay36) by smtp.aliyun-inc.com; Fri, 07 Feb 2025 17:44:29 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: david@redhat.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/6] mm: shmem: remove 'fadvise()' comments Date: Fri, 7 Feb 2025 17:44:18 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Similar to commit 255ff62d1586 ("docs: tmpfs: drop 'fadvise()' from the documentation"), fadvise() has no HUGEPAGE advise currently. Remove the confusing fadvise() comments. Signed-off-by: Baolin Wang --- mm/shmem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index ddf800357e7a..b7aef4f0a427 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -525,9 +525,9 @@ static bool shmem_confirm_swap(struct address_space *ma= pping, * enables huge pages for the mount; * SHMEM_HUGE_WITHIN_SIZE: * only allocate huge pages if the page will be fully within i_size, - * also respect fadvise()/madvise() hints; + * also respect madvise() hints; * SHMEM_HUGE_ADVISE: - * only allocate huge pages if requested with fadvise()/madvise(); + * only allocate huge pages if requested with madvise(); */ =20 #define SHMEM_HUGE_NEVER 0 --=20 2.39.3 From nobody Wed Feb 11 05:04:55 2026 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4ABDE1DE3B6 for ; Fri, 7 Feb 2025 09:44:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921482; cv=none; b=sv0+ioSD1OBJ/FsV7ll8qBuRF7xiOH9s2q6sclrIXS8EqoBukikLec25ZAKsZ3hnXa26Jaa/cpxFdkMw5w2TJwCMwlPYKxhwK+5eGh9pU6S/1WtopxTXSrK/81jyW9E1IAbIuiBKQPgRHZJ6RpCGmPUfSI+xRARRVd2hLEtV9tY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921482; c=relaxed/simple; bh=lZc4MSW/5wBHYM5x386uvX7j/sz6rzQpwfZIBMZc8nw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=V4qez9UatZ6DP6fZF7KY9CbHnbWq+tg8OdnsWL4ko8fQSMM+ujgsjqsNldTwtzUIpbVbErYCcFLLyNDDJMxfJcXpQHfZq2EltuqbPVKnl0xpn1cGhxlElFX1h0OLLC+7hmgnfT8rrjXC2rbOeEsBbIuZusfEU3oX3/Gke7YZbO4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=ARt1+6yn; arc=none smtp.client-ip=115.124.30.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="ARt1+6yn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1738921470; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=ET2M5RfKIACOkV7gUbUijh4rZv1dga746bLIAUCkeds=; b=ARt1+6ynaSnsUEeCfIwpXp5pEBRDESy5GBQEjbRk4Cbzjm1+amHm5e8EFfPTcRo3UwOGjiL/Spk/oArGH8I9EBSWjfyXPEC/VrQMrmYzfuVzzu/CjqjHgo8hCt1ydkpIXw/gzzBwV8ABaR5BBzKzUZsbNlBJVj730OzoxIZe9S4= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WOz4ok4_1738921470 cluster:ay36) by smtp.aliyun-inc.com; Fri, 07 Feb 2025 17:44:30 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: david@redhat.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/6] mm: shmem: remove duplicate error validation Date: Fri, 7 Feb 2025 17:44:19 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove duplicate error code checks for 'start' and 'end', as the get_order_from_str() will only return -EINVAL if the cmdline string is configured incorrectly. Signed-off-by: Baolin Wang --- mm/shmem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index b7aef4f0a427..b764ad336598 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -5650,19 +5650,19 @@ static int __init setup_thp_shmem(char *str) THP_ORDERS_ALL_FILE_DEFAULT); } =20 - if (start =3D=3D -EINVAL) { + if (start < 0) { pr_err("invalid size %s in thp_shmem boot parameter\n", start_size); goto err; } =20 - if (end =3D=3D -EINVAL) { + if (end < 0) { pr_err("invalid size %s in thp_shmem boot parameter\n", end_size); goto err; } =20 - if (start < 0 || end < 0 || start > end) + if (start > end) goto err; =20 nr =3D end - start + 1; --=20 2.39.3 From nobody Wed Feb 11 05:04:55 2026 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 621171A2381 for ; Fri, 7 Feb 2025 09:44:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.112 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921479; cv=none; b=INB7qECrUlpAXOw/j7UoANuu3O+wIl1YtYpkGp+mnuEWudrextRPnGRnHD/0jGhYKwphQnMqBhRsQQmHiRGbu3mgXM3XkeDvaVSlK19k4RPloUaRg3fsZiAac32JpOSrsdKMY+uvHa7TBT1CxBUmbrYdSf3vwKf9jIUvbtmoopQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921479; c=relaxed/simple; bh=Bn8cN8EuTTOa2Tul9uX/XQvuP9MbPwyRlKDWxAAAmRU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=H18t+zIFyhrIy9IgZrzuuTiw6bc1XaSA8fTz4smQvaMtDQylPIMUIiv0nQaXjNb7mS8Kaldi5av+Gt+ewl/E1OeJn6MAgW0T1lIVE8CMkZ0mxlhjR/0rH7drfhUwQX8RwGiQnkMM7D3fMc4OhyOYobs/hcmNS0n1oumCAGtxrQA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=bGM4ZQm2; arc=none smtp.client-ip=115.124.30.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="bGM4ZQm2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1738921471; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=kcZEGoLAZWYmpxFrSA4KxILcMvDpALoGBVXuA8rwiuA=; b=bGM4ZQm2T+6qFM4Vh9dklNqjJSxaxY3ErMKtdiuA1RrVrwrHRCAbH3WWsEj9KPRxYhtgtvo5aHRF1CxOTIcKmbOBqP5+32o2Ldbxlr8c/Uyfg/Rg7hOLR7xGdUGQVGbp872N2aBMo+OF37uxq+QoxAoz/wySKKrvoMVDh92b0YM= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WOz4okK_1738921470 cluster:ay36) by smtp.aliyun-inc.com; Fri, 07 Feb 2025 17:44:30 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: david@redhat.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/6] mm: shmem: change the return value of shmem_find_swap_entries() Date: Fri, 7 Feb 2025 17:44:20 +0800 Message-Id: <070489b5946b8379b2a2d25f78115cef167cd145.1738918357.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The shmem_find_swap_entries() originally returned the index corresponding to the swap entry, but no callers used this return value. It should return the number of entries that were found like other functions, which can be used by the callers. No functional changes. Signed-off-by: Baolin Wang --- mm/shmem.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index b764ad336598..c243d814f2b0 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1379,9 +1379,9 @@ static void shmem_evict_inode(struct inode *inode) #endif } =20 -static int shmem_find_swap_entries(struct address_space *mapping, - pgoff_t start, struct folio_batch *fbatch, - pgoff_t *indices, unsigned int type) +static unsigned int shmem_find_swap_entries(struct address_space *mapping, + pgoff_t start, struct folio_batch *fbatch, + pgoff_t *indices, unsigned int type) { XA_STATE(xas, &mapping->i_pages, start); struct folio *folio; @@ -1414,7 +1414,7 @@ static int shmem_find_swap_entries(struct address_spa= ce *mapping, } rcu_read_unlock(); =20 - return xas.xa_index; + return folio_batch_count(fbatch); } =20 /* @@ -1461,8 +1461,8 @@ static int shmem_unuse_inode(struct inode *inode, uns= igned int type) =20 do { folio_batch_init(&fbatch); - shmem_find_swap_entries(mapping, start, &fbatch, indices, type); - if (folio_batch_count(&fbatch) =3D=3D 0) { + if (!shmem_find_swap_entries(mapping, start, &fbatch, + indices, type)) { ret =3D 0; break; } --=20 2.39.3 From nobody Wed Feb 11 05:04:55 2026 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE3CD1DE887 for ; Fri, 7 Feb 2025 09:44:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.110 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921483; cv=none; b=YtGZ9vCGEDQSBqGjwtfbHgwz9h4eHc6hAC2goMIl7U+f0Wgg8ni2uXtZyg9kwNOV/uHdYPEINfv78/qHBCWRPcIZSYONIry8igFXTuCzhalcXFF7GM0JsISHCy0xNMCuCwptUdNZGL1EDCTF1n6BO/lNrgyzuR5z/A/hv9zjeSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921483; c=relaxed/simple; bh=gxmmTecUrLY2z0u8yBant1fbdWds+nAECV3+pMx/Ers=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ob3AzPtYTVkr8Lg/tMZaHRQZNBmSDEe+3i0Y5CpjzXpg3VamQ6sDYJaBj1PhnOvjLriSto+ZJgZqQ5DrEzde/KyBtiJpXBvFfWLt0mtYOBZ1Yql2/vNc9Pysh8ILnEMyfrnTYoxetg+TRJeGy6E9TEXyY9qGd9HvJ4v2/U0xvko= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=oMbqE4Uv; arc=none smtp.client-ip=115.124.30.110 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="oMbqE4Uv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1738921472; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=3PS22iDEZK02vBCkQcniOhhJpKU1weoXF4MOKLaGix0=; b=oMbqE4Uv00/zuNB+vQ/BwfUVYClGY9Hhs6mBblpKB2ysEJKVjoYlXRKyGPlKoyXoJZRNls4ekMwuwRcV+AYapQy//UowJe40KwbSF9ZyK21QFYbOfhv7zYcN4DZHWuOHtQyozcFX/rP0jvf9bsIpKPvYjp/x+PhHtWkMeW7hn8w= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WOz6dmv_1738921471 cluster:ay36) by smtp.aliyun-inc.com; Fri, 07 Feb 2025 17:44:31 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: david@redhat.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/6] mm: shmem: factor out the within_size logic into a new helper Date: Fri, 7 Feb 2025 17:44:21 +0800 Message-Id: <527dea9d7e32fe6b94c7fe00df2c126203017911.1738918357.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Factor out the within_size logic into a new helper to remove duplicate code. Suggested-by: David Hildenbrand Signed-off-by: Baolin Wang --- mm/shmem.c | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index c243d814f2b0..671f63063fd4 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -590,6 +590,28 @@ shmem_mapping_size_orders(struct address_space *mappin= g, pgoff_t index, loff_t w return order > 0 ? BIT(order + 1) - 1 : 0; } =20 +static unsigned int shmem_get_orders_within_size(struct inode *inode, + unsigned long within_size_orders, pgoff_t index, + loff_t write_end) +{ + pgoff_t aligned_index; + unsigned long order; + loff_t i_size; + + order =3D highest_order(within_size_orders); + while (within_size_orders) { + aligned_index =3D round_up(index + 1, 1 << order); + i_size =3D max(write_end, i_size_read(inode)); + i_size =3D round_up(i_size, PAGE_SIZE); + if (i_size >> PAGE_SHIFT >=3D aligned_index) + return within_size_orders; + + order =3D next_order(&within_size_orders, order); + } + + return 0; +} + static unsigned int shmem_huge_global_enabled(struct inode *inode, pgoff_t= index, loff_t write_end, bool shmem_huge_force, struct vm_area_struct *vma, @@ -598,9 +620,6 @@ static unsigned int shmem_huge_global_enabled(struct in= ode *inode, pgoff_t index unsigned int maybe_pmd_order =3D HPAGE_PMD_ORDER > MAX_PAGECACHE_ORDER ? 0 : BIT(HPAGE_PMD_ORDER); unsigned long within_size_orders; - unsigned int order; - pgoff_t aligned_index; - loff_t i_size; =20 if (!S_ISREG(inode->i_mode)) return 0; @@ -634,16 +653,11 @@ static unsigned int shmem_huge_global_enabled(struct = inode *inode, pgoff_t index within_size_orders =3D shmem_mapping_size_orders(inode->i_mapping, index, write_end); =20 - order =3D highest_order(within_size_orders); - while (within_size_orders) { - aligned_index =3D round_up(index + 1, 1 << order); - i_size =3D max(write_end, i_size_read(inode)); - i_size =3D round_up(i_size, PAGE_SIZE); - if (i_size >> PAGE_SHIFT >=3D aligned_index) - return within_size_orders; + within_size_orders =3D shmem_get_orders_within_size(inode, within_size_o= rders, + index, write_end); + if (within_size_orders > 0) + return within_size_orders; =20 - order =3D next_order(&within_size_orders, order); - } fallthrough; case SHMEM_HUGE_ADVISE: if (vm_flags & VM_HUGEPAGE) @@ -1756,10 +1770,7 @@ unsigned long shmem_allowable_huge_orders(struct ino= de *inode, unsigned long mask =3D READ_ONCE(huge_shmem_orders_always); unsigned long within_size_orders =3D READ_ONCE(huge_shmem_orders_within_s= ize); unsigned long vm_flags =3D vma ? vma->vm_flags : 0; - pgoff_t aligned_index; unsigned int global_orders; - loff_t i_size; - int order; =20 if (thp_disabled_by_hw() || (vma && vma_thp_disabled(vma, vm_flags))) return 0; @@ -1785,17 +1796,7 @@ unsigned long shmem_allowable_huge_orders(struct ino= de *inode, return READ_ONCE(huge_shmem_orders_inherit); =20 /* Allow mTHP that will be fully within i_size. */ - order =3D highest_order(within_size_orders); - while (within_size_orders) { - aligned_index =3D round_up(index + 1, 1 << order); - i_size =3D round_up(i_size_read(inode), PAGE_SIZE); - if (i_size >> PAGE_SHIFT >=3D aligned_index) { - mask |=3D within_size_orders; - break; - } - - order =3D next_order(&within_size_orders, order); - } + mask |=3D shmem_get_orders_within_size(inode, within_size_orders, index, = 0); =20 if (vm_flags & VM_HUGEPAGE) mask |=3D READ_ONCE(huge_shmem_orders_madvise); --=20 2.39.3 From nobody Wed Feb 11 05:04:55 2026 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 84DBB1A23A9 for ; Fri, 7 Feb 2025 09:44:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.112 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921479; cv=none; b=WJRErxJkkqN12CraSfOeuPekjwHwumqR6DvoJhxxdWxNPgNQQrgIVIrkNUUQTY5pKF5b2d3bzNjzyFZXYza57tpWirw1ObcFA/90cHU+alX3q3vRu2gpNuQOJ2dY8ZX2CVlQXrhKIbLxwVX51iRBpcDE6/vLQuCl5DyT1/361T0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921479; c=relaxed/simple; bh=d2ITcAefxdIh0F5/1MMFs5XE0rGFN5d1sS+KU0R/OBs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kx5FLwn4sw29R12ghsn2HLqOh9RuMKbzEOnWjW+sxQYYZXOYF32yBzUwsj6WY3BWLRiJaYmJTy7jMsMF7hDN4WBGITgcyUvLU8fgKlloD/0LtqjrbllzAun0l9hF/vB+6Xpi7zPlJ6MLY/Gr4FLr1vb0DdMLeJv1vM1W9HWLDQo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=i7gHCJj2; arc=none smtp.client-ip=115.124.30.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="i7gHCJj2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1738921472; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=EGHE22JNOgVTm0fKKQ9rTbfnsV4oV5XFAO63xRbgM58=; b=i7gHCJj2w+RxG2tEUTFWIBVb+fcCZ/rk1BGqLQ3+mYoJGmiXP/ULHwnIzOk6nLiA4yJevicKiWcRAs7q9l+O3/gCGWlR6jL+dN/LX8SV0qTK+sIVpfDUCOP4+Cki7d0BY/doI/Bllla+vgDhs3dYtieHR9i32yXYyKU46yylCPU= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WOz4okr_1738921471 cluster:ay36) by smtp.aliyun-inc.com; Fri, 07 Feb 2025 17:44:32 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: david@redhat.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/6] MAINTAINERS: add myself as shmem reviewer Date: Fri, 7 Feb 2025 17:44:22 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In the past year, I've primarily focused on shmem and added several features to it, such as support for mTHP, large folio swap-out and swap-in support, mTHP collapse support, skipping swapcache, and tmpfs support for large foli= os, and so on. Meanwhile I've also been helping with testing and reviewing shmem related patches. So I am willing to continue assisting with testing and reviewing shmem related patches. Let me be Cc'd on patches related to shmem. Signed-off-by: Baolin Wang --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 577592e3af82..7fe4ea237afe 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -23883,6 +23883,7 @@ F: drivers/hwmon/tmp513.c =20 TMPFS (SHMEM FILESYSTEM) M: Hugh Dickins +R: Baolin Wang L: linux-mm@kvack.org S: Maintained F: include/linux/shmem_fs.h --=20 2.39.3