From patchwork Tue Jun 4 10:58:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usama Arif X-Patchwork-Id: 13685068 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9790C27C50 for ; Tue, 4 Jun 2024 11:00:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A21E6B00AE; Tue, 4 Jun 2024 07:00:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 653F66B00B7; Tue, 4 Jun 2024 07:00:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4CA776B00BA; Tue, 4 Jun 2024 07:00:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3133B6B00AE for ; Tue, 4 Jun 2024 07:00:03 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CCA9EC0ED8 for ; Tue, 4 Jun 2024 11:00:02 +0000 (UTC) X-FDA: 82192911444.14.ABF2371 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) by imf30.hostedemail.com (Postfix) with ESMTP id D608980008 for ; Tue, 4 Jun 2024 11:00:00 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Esnq1W9d; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.219.54 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717498800; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=asgpbMnZY0t8v6Jl3H5uUs1NISRsXbBHVciypDjEWY8=; b=ZmkZPit9O079WJ88pFulszYU7fbqUpV/pDet9Yvp1rglDiE4wr7UUnJ5laH/5w81+j/JK6 OjzoRW22OSeFX4CrCiv7GGHh/UFSvhZJ+ACZ62LtMrEkWmBMneSfkfUcC7IaEZpjw7qEed J4f97pdpp+LvCE7w+DraT+Lgpz88ttc= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Esnq1W9d; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.219.54 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717498800; a=rsa-sha256; cv=none; b=6etG9k+mkJFghQ0HzL/vUu8V4MFnhkX+U19/0F7oAisW3qxD8JPgu0b11W2Gy/oTSucu0n CKzPS2ZJYUqOK96B3lnYO6jeXR57kUig9Hkni7espXga+a+i2Sc8ZbJBni++K8rimzEkB5 r3aeIbdEEWUv+Vb6qCKEtvWNeZC2Dbk= Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-6af55412d69so3686976d6.2 for ; Tue, 04 Jun 2024 04:00:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717498800; x=1718103600; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=asgpbMnZY0t8v6Jl3H5uUs1NISRsXbBHVciypDjEWY8=; b=Esnq1W9dKRf8s2iJTfxc1toWWrbl7eQ2JbzQ1U6u9N0fV3Jh3SR+lh4gYhqtwEDqOp oOlKc2onc+FAA2uUZR4vruiDsiooyTlIY8slw2LyVZOxsC50rOwJAeNWYSxiUPqotad6 ruzQC1s32ukeceGLst+4ASN0y8YuybvsGEzWNZfCUXgO6tuLO7uIP4xi58pb4AsbQM0C BFaxoaNGH80xfxfBGTP6eLP3Qnju74e8pXnAsb3Xte9YyGBkm9ytrZqLMxCCecjI8yze YjchMMW5WWKmKpwFbN44EA73FuAPsT5qlA92MVTObExwX4ZPTnP53puFpcDB5W/oPSDV hAEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717498800; x=1718103600; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=asgpbMnZY0t8v6Jl3H5uUs1NISRsXbBHVciypDjEWY8=; b=hiADHFZkDpIgkcPEVDyzDKo7e8lcE5wmn3d6rSAaufmjxIuxenzTHriqqtI/Q8yKRP LSDVnkCpFxmPO3vhpzaUeFEg+LRbZVw+NhHlVsxNwTP38d72jm1Ak2Ropi/xO63zlJTI TgwOWTNOe9lViMZfcGR+z9MMoj7LwlW+xezc0bR/8T/Cgf/tbNj+GHvGEZ1eXQAKfexC DVfDIoTYJPc0Q1/4v4jWZuBMcmWbpuE5GfbVbpAtdlKcItjMPZNS8mxl9FDulMAYB/Qt YZn2QO2QvHyPnDDFekwruxR2DfWMF79pEP1ZCTi/e9QM1kTPm70giFGZFf6mrfLFLKOk tc2A== X-Forwarded-Encrypted: i=1; AJvYcCXucnhPFISS8lwvfLn5UGp5QK2NhCqEFNzIBpsJbNpMJbecMu87ZT/TK9fTuJdWLIFCSTPUcC68bNACzQCUaOELuXY= X-Gm-Message-State: AOJu0YyX6zZrLWzT3SM+Fltipr2nmA5YuTAgHTVZrEFWMhoePOxNrExU PqRbfJ9Dz4b7aZndA9R5yjk8ZUGMK3X2MopZ0wW23iDhoTzrUlIJ X-Google-Smtp-Source: AGHT+IElTPVikfDZzSypb4x9WPBEWXCiurpJs66Y0afsj9XrVePVVfBdFKw3gJ79SVsC2AzYhyprtg== X-Received: by 2002:a05:6214:2b88:b0:6af:bf15:3600 with SMTP id 6a1803df08f44-6afbf153bd7mr57304046d6.38.1717498799747; Tue, 04 Jun 2024 03:59:59 -0700 (PDT) Received: from localhost (fwdproxy-nao-000.fbsv.net. [2a03:2880:23ff::face:b00c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6afc6696d05sm13797306d6.73.2024.06.04.03.59.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 03:59:58 -0700 (PDT) From: Usama Arif To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, willy@infradead.org, yosryahmed@google.com, nphamcs@gmail.com, chengming.zhou@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, Usama Arif Subject: [PATCH v2 1/2] mm: clear pte for folios that are zero filled Date: Tue, 4 Jun 2024 11:58:24 +0100 Message-ID: <20240604105950.1134192-2-usamaarif642@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240604105950.1134192-1-usamaarif642@gmail.com> References: <20240604105950.1134192-1-usamaarif642@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: D608980008 X-Stat-Signature: gpbjh9t94w9mdszgeqqazwnsebfaz5jt X-HE-Tag: 1717498800-414319 X-HE-Meta: U2FsdGVkX19X/4vjn7xm8+naKTtL4h7tKdj15v1sGv927g3ebPzv9fIALDe4R02MeYrH0Eyr0g6BhEmX32fcUwmK809HgYsgy7ZRrUwig7m4CrrhLDItLYnNQ6v2J1sv4JfjIX9MIoAkyUP/kjQl9mezvBySLyVNymnVs4XtxiHQ+CXI7qUuZ345VywVpUA5/kRkMgmI1FtWbwk5lsl7insLcwJf8Ng7QSfSXF6j3LbK9KpH4+altXSsQVme3R8Q8l54Gz33olQm/jdFFaQE1X4cUF3xImtszi0+N0kaWJWpmO3tagcoP/p/JHYpaB80pPHTDJm6KgVsE0JvKWcohQe3rk4esT7XPSy/u3zqkH2O5xzYVXkr7gn3chqMaaAoFSvc3p1ezhj7d41nPTgtlGJPzzRCjSqyOSFxbU8FJpqSxHmr2bZmPAsIx55h4HseVD14lI/VbO1s7qzqjjmmGPtgGfoGLsWRZ9Y9afcsagrOp2NIguBupJfmf9wzdajut1njJmF7Hsv9YiBp6oMT+RYAe8QtjCeBYrmZ8qkRi/CSqB3tkeY39s6n09T1atY0qNyJoxsYDOxpuKdmswUxeNwCWSY2kHknRuED3lXxsCQTH1X8zUmamgKMAxvjWXa+xgMnyoxAH3ivFS2xsyNrjh0WvPHZ2UIhiDgfSPAuVbnRlikVnIjHcPFJk1HxTdwYREF4AydsP7FxJq6pbPVL3X9xiZ5QaPmxy9qm18zq+ZYjkBJhxP46SP+pPbu7UvZ0p6MD5Cjf2aK4E2jjhiB78vb+Tbu70pUZ5l6f3QRwXHR3tBDN6ng6xTXHt7YY0M5wm3YQOzTj9ayuqzHvFu54hsFG44rCwYjJhcoxw7OLpES9S7+d5fG4622fm9Rlvl3gPm/d9y5+5hYw6m5Q8xktgkH/qf6PXy5oa/vocAcmEIn1vgXQ4whTT8zLjWkojE0zp5ZdJPDkgN0GEOmFf+f bDjFfRX2 lzmH6TIflDiBZF2vn+xYmp+uWgsbMm2/kIWJcmzsVEezydV3J2fcfWkytIq2myWR9gs7cDdLRXGXCzXMHqsORrGQ80zRMldMWh2hTYwPwSmEpzc+cCdpS2jg/tgKrYteBxNrVfT22Vn/HWzX5e2G7SkGA8AzQb1PGSZFI/wFooakX3LTQUZ9cxs51M+J7ZD2YsL4Om+1Ir0XTNdacAjwYVW2wOW9eDBFcapF4VdD06fOUqYtkPM92GvCUzjqDfKYWYUlF5ywWr33bWu+KWWdHzUcfgF7IRKqgYvJTFY5mYR/pcZlWmzX6E4M89xEn1tvatSQsaUTbamBgn5Rph9KXL1PaeCQiyTnup7kmTnYDBXp2Y8LlvzuQ7nE0ujkL9rwQp/5V20cb8aecLkQl+pr1BeETaE7kM7p4Y/BUCyWdikwhg2l1SgcdzsY0pgm9gC6QlSroecfwb/yNcYZcRoJgHcdKuuO+/Wud2HlOvjf4c7odY9o= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Approximately 10-20% of pages to be swapped out are zero pages [1]. Rather than reading/writing these pages to flash resulting in increased I/O and flash wear, the pte can be cleared for those addresses at unmap time while shrinking folio list. When this causes a page fault, do_pte_missing will take care of this page. With this patch, NVMe writes in Meta server fleet decreased by almost 10% with conventional swap setup (zswap disabled). [1] https://lore.kernel.org/all/20171018104832epcms5p1b2232e2236258de3d03d1344dde9fce0@epcms5p1/ Signed-off-by: Usama Arif --- include/linux/rmap.h | 1 + mm/rmap.c | 163 ++++++++++++++++++++++--------------------- mm/vmscan.c | 89 ++++++++++++++++------- 3 files changed, 150 insertions(+), 103 deletions(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index bb53e5920b88..b36db1e886e4 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -100,6 +100,7 @@ enum ttu_flags { * do a final flush if necessary */ TTU_RMAP_LOCKED = 0x80, /* do not grab rmap lock: * caller holds it */ + TTU_ZERO_FOLIO = 0x100,/* zero folio */ }; #ifdef CONFIG_MMU diff --git a/mm/rmap.c b/mm/rmap.c index 52357d79917c..d98f70876327 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1819,96 +1819,101 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, */ dec_mm_counter(mm, mm_counter(folio)); } else if (folio_test_anon(folio)) { - swp_entry_t entry = page_swap_entry(subpage); - pte_t swp_pte; - /* - * Store the swap location in the pte. - * See handle_pte_fault() ... - */ - if (unlikely(folio_test_swapbacked(folio) != - folio_test_swapcache(folio))) { + if (flags & TTU_ZERO_FOLIO) { + pte_clear(mm, address, pvmw.pte); + dec_mm_counter(mm, MM_ANONPAGES); + } else { + swp_entry_t entry = page_swap_entry(subpage); + pte_t swp_pte; /* - * unmap_huge_pmd_locked() will unmark a - * PMD-mapped folio as lazyfree if the folio or - * its PMD was redirtied. + * Store the swap location in the pte. + * See handle_pte_fault() ... */ - if (!pmd_mapped) - WARN_ON_ONCE(1); - goto walk_done_err; - } + if (unlikely(folio_test_swapbacked(folio) != + folio_test_swapcache(folio))) { + /* + * unmap_huge_pmd_locked() will unmark a + * PMD-mapped folio as lazyfree if the folio or + * its PMD was redirtied. + */ + if (!pmd_mapped) + WARN_ON_ONCE(1); + goto walk_done_err; + } - /* MADV_FREE page check */ - if (!folio_test_swapbacked(folio)) { - int ref_count, map_count; + /* MADV_FREE page check */ + if (!folio_test_swapbacked(folio)) { + int ref_count, map_count; - /* - * Synchronize with gup_pte_range(): - * - clear PTE; barrier; read refcount - * - inc refcount; barrier; read PTE - */ - smp_mb(); + /* + * Synchronize with gup_pte_range(): + * - clear PTE; barrier; read refcount + * - inc refcount; barrier; read PTE + */ + smp_mb(); - ref_count = folio_ref_count(folio); - map_count = folio_mapcount(folio); + ref_count = folio_ref_count(folio); + map_count = folio_mapcount(folio); - /* - * Order reads for page refcount and dirty flag - * (see comments in __remove_mapping()). - */ - smp_rmb(); + /* + * Order reads for page refcount and dirty flag + * (see comments in __remove_mapping()). + */ + smp_rmb(); - /* - * The only page refs must be one from isolation - * plus the rmap(s) (dropped by discard:). - */ - if (ref_count == 1 + map_count && - !folio_test_dirty(folio)) { - dec_mm_counter(mm, MM_ANONPAGES); - goto discard; - } + /* + * The only page refs must be one from isolation + * plus the rmap(s) (dropped by discard:). + */ + if (ref_count == 1 + map_count && + !folio_test_dirty(folio)) { + dec_mm_counter(mm, MM_ANONPAGES); + goto discard; + } - /* - * If the folio was redirtied, it cannot be - * discarded. Remap the page to page table. - */ - set_pte_at(mm, address, pvmw.pte, pteval); - folio_set_swapbacked(folio); - goto walk_done_err; - } + /* + * If the folio was redirtied, it cannot be + * discarded. Remap the page to page table. + */ + set_pte_at(mm, address, pvmw.pte, pteval); + folio_set_swapbacked(folio); + goto walk_done_err; + } - if (swap_duplicate(entry) < 0) { - set_pte_at(mm, address, pvmw.pte, pteval); - goto walk_done_err; - } - if (arch_unmap_one(mm, vma, address, pteval) < 0) { - swap_free(entry); - set_pte_at(mm, address, pvmw.pte, pteval); - goto walk_done_err; - } + if (swap_duplicate(entry) < 0) { + set_pte_at(mm, address, pvmw.pte, pteval); + goto walk_done_err; + } + if (arch_unmap_one(mm, vma, address, pteval) < 0) { + swap_free(entry); + set_pte_at(mm, address, pvmw.pte, pteval); + goto walk_done_err; + } - /* See folio_try_share_anon_rmap(): clear PTE first. */ - if (anon_exclusive && - folio_try_share_anon_rmap_pte(folio, subpage)) { - swap_free(entry); - set_pte_at(mm, address, pvmw.pte, pteval); - goto walk_done_err; - } - if (list_empty(&mm->mmlist)) { - spin_lock(&mmlist_lock); - if (list_empty(&mm->mmlist)) - list_add(&mm->mmlist, &init_mm.mmlist); - spin_unlock(&mmlist_lock); + /* See folio_try_share_anon_rmap(): clear PTE first. */ + if (anon_exclusive && + folio_try_share_anon_rmap_pte(folio, subpage)) { + swap_free(entry); + set_pte_at(mm, address, pvmw.pte, pteval); + goto walk_done_err; + } + if (list_empty(&mm->mmlist)) { + spin_lock(&mmlist_lock); + if (list_empty(&mm->mmlist)) + list_add(&mm->mmlist, &init_mm.mmlist); + spin_unlock(&mmlist_lock); + } + dec_mm_counter(mm, MM_ANONPAGES); + inc_mm_counter(mm, MM_SWAPENTS); + swp_pte = swp_entry_to_pte(entry); + if (anon_exclusive) + swp_pte = pte_swp_mkexclusive(swp_pte); + if (pte_soft_dirty(pteval)) + swp_pte = pte_swp_mksoft_dirty(swp_pte); + if (pte_uffd_wp(pteval)) + swp_pte = pte_swp_mkuffd_wp(swp_pte); + set_pte_at(mm, address, pvmw.pte, swp_pte); } - dec_mm_counter(mm, MM_ANONPAGES); - inc_mm_counter(mm, MM_SWAPENTS); - swp_pte = swp_entry_to_pte(entry); - if (anon_exclusive) - swp_pte = pte_swp_mkexclusive(swp_pte); - if (pte_soft_dirty(pteval)) - swp_pte = pte_swp_mksoft_dirty(swp_pte); - if (pte_uffd_wp(pteval)) - swp_pte = pte_swp_mkuffd_wp(swp_pte); - set_pte_at(mm, address, pvmw.pte, swp_pte); } else { /* * This is a locked file-backed folio, diff --git a/mm/vmscan.c b/mm/vmscan.c index b9170f767353..d54f44b556f0 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1026,6 +1026,38 @@ static bool may_enter_fs(struct folio *folio, gfp_t gfp_mask) return !data_race(folio_swap_flags(folio) & SWP_FS_OPS); } +static bool is_folio_page_zero_filled(struct folio *folio, int i) +{ + unsigned long *data; + unsigned int pos, last_pos = PAGE_SIZE / sizeof(*data) - 1; + bool ret = false; + + data = kmap_local_folio(folio, i * PAGE_SIZE); + + if (data[last_pos]) + goto out; + + for (pos = 0; pos < last_pos; pos++) { + if (data[pos]) + goto out; + } + ret = true; +out: + kunmap_local(data); + return ret; +} + +static bool is_folio_zero_filled(struct folio *folio) +{ + unsigned int i; + + for (i = 0; i < folio_nr_pages(folio); i++) { + if (!is_folio_page_zero_filled(folio, i)) + return false; + } + return true; +} + /* * shrink_folio_list() returns the number of reclaimed pages */ @@ -1053,6 +1085,7 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, enum folio_references references = FOLIOREF_RECLAIM; bool dirty, writeback; unsigned int nr_pages; + bool folio_zero_filled = false; cond_resched(); @@ -1270,6 +1303,7 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, nr_pages = 1; } + folio_zero_filled = is_folio_zero_filled(folio); /* * The folio is mapped into the page tables of one or more * processes. Try to unmap it here. @@ -1295,6 +1329,9 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, if (folio_test_large(folio) && list_empty(&folio->_deferred_list)) flags |= TTU_SYNC; + if (folio_zero_filled) + flags |= TTU_ZERO_FOLIO; + try_to_unmap(folio, flags); if (folio_mapped(folio)) { stat->nr_unmap_fail += nr_pages; @@ -1358,32 +1395,36 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, * starts and then write it out here. */ try_to_unmap_flush_dirty(); - switch (pageout(folio, mapping, &plug)) { - case PAGE_KEEP: - goto keep_locked; - case PAGE_ACTIVATE: - goto activate_locked; - case PAGE_SUCCESS: - stat->nr_pageout += nr_pages; + if (folio_zero_filled) { + folio_clear_dirty(folio); + } else { + switch (pageout(folio, mapping, &plug)) { + case PAGE_KEEP: + goto keep_locked; + case PAGE_ACTIVATE: + goto activate_locked; + case PAGE_SUCCESS: + stat->nr_pageout += nr_pages; - if (folio_test_writeback(folio)) - goto keep; - if (folio_test_dirty(folio)) - goto keep; + if (folio_test_writeback(folio)) + goto keep; + if (folio_test_dirty(folio)) + goto keep; - /* - * A synchronous write - probably a ramdisk. Go - * ahead and try to reclaim the folio. - */ - if (!folio_trylock(folio)) - goto keep; - if (folio_test_dirty(folio) || - folio_test_writeback(folio)) - goto keep_locked; - mapping = folio_mapping(folio); - fallthrough; - case PAGE_CLEAN: - ; /* try to free the folio below */ + /* + * A synchronous write - probably a ramdisk. Go + * ahead and try to reclaim the folio. + */ + if (!folio_trylock(folio)) + goto keep; + if (folio_test_dirty(folio) || + folio_test_writeback(folio)) + goto keep_locked; + mapping = folio_mapping(folio); + fallthrough; + case PAGE_CLEAN: + ; /* try to free the folio below */ + } } } From patchwork Tue Jun 4 10:58:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Usama Arif X-Patchwork-Id: 13685069 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60ED8C25B7E for ; Tue, 4 Jun 2024 11:00:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC1286B00BC; Tue, 4 Jun 2024 07:00:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A70B86B00BD; Tue, 4 Jun 2024 07:00:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E92A6B00BE; Tue, 4 Jun 2024 07:00:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 72BE86B00BC for ; Tue, 4 Jun 2024 07:00:06 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 217D4A1B1E for ; Tue, 4 Jun 2024 11:00:06 +0000 (UTC) X-FDA: 82192911612.14.5431071 Received: from mail-oi1-f175.google.com (mail-oi1-f175.google.com [209.85.167.175]) by imf10.hostedemail.com (Postfix) with ESMTP id 24F58C0035 for ; Tue, 4 Jun 2024 11:00:02 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JpQOME+X; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.167.175 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717498803; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5+XY1gPxeVwDTMFWy18KTOJW5+R0TdSJWJS675lM6zM=; b=DeKnKenQwKD3PY7MFlFjYRbSevtLvD/yNTJNJIY77kr3h5jCVCmk+A03hdu6vxnzD4fBBM ln5pfeSNciuJphFwaeCgGfYdW8AnXyGFRtko37ZSxGUfEC5FxLE3Lf2XHcm6DdgSgWx0XD NTl/SVJ7aWwdCll6U73PUdEk4rgKvV8= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JpQOME+X; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of usamaarif642@gmail.com designates 209.85.167.175 as permitted sender) smtp.mailfrom=usamaarif642@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717498803; a=rsa-sha256; cv=none; b=R+ByevJP10nJt5p2ruVM/6MoI71Lk+w4AdPcOcu11oS7bGZ/g8lsRo0Gw9hATZrDLyphoh MMC+RpWMmRf+F8PVagBdbvh9Si6/IwSGf+dwMfGYNfb+PCvlILW2mFBmnkQokABpgIpRYn 5KFe8oWPVVmB8ubUd57QmWq8TJ4QO64= Received: by mail-oi1-f175.google.com with SMTP id 5614622812f47-3d1fea41751so178490b6e.2 for ; Tue, 04 Jun 2024 04:00:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717498802; x=1718103602; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5+XY1gPxeVwDTMFWy18KTOJW5+R0TdSJWJS675lM6zM=; b=JpQOME+XfveF1BsD1y8w3sCyf14jzqfy13DYJ0kF1Jh/j7wFJDhuX8R8KRQBc6m6oY LCPByNaJBa+eGb5VfNrPTBSCeqG3asCdKGOkVUoLGJZbHlIICLt99r0jGh5NlHS6jRPS O3BqtW2v3lLK4c2e4Rf5oIBkM7VrtRJy9v2IXLjrSgIKfsuaDXBiY2mz8wYjfCETHraG 5imEW1KCOJ+UvqFr+9yAmrmnzCQ8rGEz5CjruAdSpbtrhzNQT/A+4lymli3miyC4ZpEK hi+RqBj3Nr4bQzAgJl8GllgKqvhtvXPYep82Wyrz7Ke7dOnQgtzGQkWF8r2faCe3XMZW ISbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717498802; x=1718103602; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5+XY1gPxeVwDTMFWy18KTOJW5+R0TdSJWJS675lM6zM=; b=U8R+nlf4zBdTE5LsYDbbG+eo0ums551P1ufx2leYtn0LGZx6nwUO/IVk12S5qU96ts FIdXV4BYn8hzAvl+3Pv7kid31fE/HfQ6xdbJ6BlXA14w2Ry39z/3qpM35DJaWe2sG4qF 2T1V9GzVvU1VkOSb2geyCdcgKNffpBdiYx7652MF8Mr2yfniIoCY3KDFyfaE24G5WgEo kk/4RmN3yPyNQXO8v4q0Pc3VblOHwSH+cXnLjVoE19COyZu5angzXsX3izsjOwPvArI8 xtkVQb1RGgwQrPtmcBcPwhjrmzvQZ1s+NCLZCwJxnYIwUwKhBG/wPFiZRYfO6xQewwuz GuPQ== X-Forwarded-Encrypted: i=1; AJvYcCXomOS0kUCrRH5BLE9uxVbKw33ifxog5E7t5Q6vWPpDtrwcdirCaPOPGZD+wMTClODlNgKGHyaBPxx3lsQ+kJrO1K8= X-Gm-Message-State: AOJu0YwVTMELflYB/lZ61zuUEHfphQUwQ+B8+oorkGyANnGe0IHDFaUF tLMpeyw/XJQhdvtyWastl0xX6C+i4yf6RWoKjdp6WT2ynsR1mqIH X-Google-Smtp-Source: AGHT+IGqjDsQMT9+d5i3I+sV8o2xgyHBJns1JSWePTCCOLgtjISL9ZlqehNIwR0a3myq26CqJC/CfQ== X-Received: by 2002:aca:280a:0:b0:3d1:c62a:3e0d with SMTP id 5614622812f47-3d1e35d0120mr10336000b6e.58.1717498801911; Tue, 04 Jun 2024 04:00:01 -0700 (PDT) Received: from localhost (fwdproxy-nao-005.fbsv.net. [2a03:2880:23ff:5::face:b00c]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6afbf044967sm18003676d6.124.2024.06.04.04.00.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 04:00:00 -0700 (PDT) From: Usama Arif To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, willy@infradead.org, yosryahmed@google.com, nphamcs@gmail.com, chengming.zhou@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, Usama Arif Subject: [PATCH v2 2/2] mm: remove code to handle same filled pages Date: Tue, 4 Jun 2024 11:58:25 +0100 Message-ID: <20240604105950.1134192-3-usamaarif642@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240604105950.1134192-1-usamaarif642@gmail.com> References: <20240604105950.1134192-1-usamaarif642@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 24F58C0035 X-Stat-Signature: sfoyjrpzgdr9jpj9pmr9zw5qjtbmrqj7 X-HE-Tag: 1717498802-762204 X-HE-Meta: U2FsdGVkX19F6USVpA6j1qWkDiSnUVgDZXHq1on7PgVLDVeMuWW2jh6YeYsB1kV+mBJDnZsqfPsPA4MrfKuP8ZVYxQzayIvReiIQCglB0EoD8jwP0h89LRaiBL5SEjDUSSKEWXqU3oUsiilRHxjQIf2N639anMluIqBXL9IuhMzKw29ZWBZDOfoBQA9U9wRSo7StCz3a269zjNzjwmbzFrc+ecd1fFucBYiXZiVYY4pRMy0uQ4CdBTc6fsZuPu2kkqJyzO7xw/sSVrVn8969OmnfGnHGAQeEbDOuX8iuTlbCKzkGG+30uNTBBPTKR8yDVqb+Lo5NXPenQkHDmRmvH/7sYWc2ClqGismRo5v7PKlQBgRH6qSrBfCYfrSkxPWGBQb6BI3Kb4NrhSS8yFJD2odvIkISkhDk+D/IIIlNtYv4wDE5A07JMm7lMMGr9tObbFtjnFS6oGOgJmILKJMjons5AAmdi2/lKrWW6tv7SbjDmA6YTRVOMcbeF0lDaZzfP76ti8SzUTNaLJ9jkBkmUnfR5iw5jMO9pX2j8B50lRySNKtVnNDw52h2ZlJZuJAq7/mNmDB1WUgpXGS82KYPNRqqeWalniHMlr6WNO4+ZwccbbwSY3QN9RIBRJ1TnfpRLUt2jCEvADkGwHOBvdozqC+NDU/h4WpdCxv2huWMODBNOorezCckcj9Qw5Cj/KwaqD0QvC14vcfV1gd3j1+DO2mGRIzRQYqmDKmI89T03Gq6FZcnjZD8UgBRoFrOyJLM3sQ9J1tbNCEubGZrp0HzEKgcNxVbYuL77UOBkJsxzVFfqu7Gx47HGv6J/4qbKoJI2O98tWIZ8HQzpcNumh4O3IVxHov8Igy6vRryXUSf/MABYBOZnLyLdoTpSUzbPtn9Hhb3YA7OcXKq1t5m2G5DqIzuYi0foPKP2l669dv+JOrTtiKlDetbUBtx7A+D/UZ7NMnIjZe3jHXSHuNHret Tn1ixXEC m95mor+Lmm5uhregpvSLE+OCvxKWs5y86g8yOSsLQvdybwEL+8/j6epGg8PoePXWbL8vxqfmpdBkN9PBDTnkW71wkcc5QvYaydDS4jgB7eOgLilE8RYu5C6uZvlNs/2eGGGLQQIm6ShVl6Rk3dZEzu8VP1W55w55NE5bTvDcNaSioivBX0e7BjaxU9L0TmLrbVxpL/8vuyHTNnwzT/TLwKnn5dlDkCUHW18veyNIEhriJJJIxUC8yda44DK3wa00llU/gXZhsXWizYCtlFblcpQ6yx/EObk4D29VCs4dHV9UhdICoLzkXRIeKwSNHbki2hYSBcKNdKhEithgE9Wxz2XTTYHBLz/CQOxdsAuaMEXSC9mkSYXmxqBqvQPFztNFer5pn/xAXjdWhzmc+Ekg5zGKEGMbp4deLG2U8pvVzsDEWMww= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: With an earlier commit to handle zero-filled pages in vmscan directly, and with only 1% of the same-filled pages being non-zero, zswap no longer needs to handle same-filled pages and can just work on compressed pages. Signed-off-by: Usama Arif --- mm/zswap.c | 86 +++++------------------------------------------------- 1 file changed, 8 insertions(+), 78 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index b9b35ef86d9b..ca8df9c99abf 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -44,8 +44,6 @@ **********************************/ /* The number of compressed pages currently stored in zswap */ atomic_t zswap_stored_pages = ATOMIC_INIT(0); -/* The number of same-value filled pages currently stored in zswap */ -static atomic_t zswap_same_filled_pages = ATOMIC_INIT(0); /* * The statistics below are not protected from concurrent access for @@ -182,11 +180,9 @@ static struct shrinker *zswap_shrinker; * * swpentry - associated swap entry, the offset indexes into the red-black tree * length - the length in bytes of the compressed page data. Needed during - * decompression. For a same value filled page length is 0, and both - * pool and lru are invalid and must be ignored. + * decompression. * pool - the zswap_pool the entry's data is in * handle - zpool allocation handle that stores the compressed page data - * value - value of the same-value filled pages which have same content * objcg - the obj_cgroup that the compressed memory is charged to * lru - handle to the pool's lru used to evict pages. */ @@ -194,10 +190,7 @@ struct zswap_entry { swp_entry_t swpentry; unsigned int length; struct zswap_pool *pool; - union { - unsigned long handle; - unsigned long value; - }; + unsigned long handle; struct obj_cgroup *objcg; struct list_head lru; }; @@ -814,13 +807,9 @@ static struct zpool *zswap_find_zpool(struct zswap_entry *entry) */ static void zswap_entry_free(struct zswap_entry *entry) { - if (!entry->length) - atomic_dec(&zswap_same_filled_pages); - else { - zswap_lru_del(&zswap_list_lru, entry); - zpool_free(zswap_find_zpool(entry), entry->handle); - zswap_pool_put(entry->pool); - } + zswap_lru_del(&zswap_list_lru, entry); + zpool_free(zswap_find_zpool(entry), entry->handle); + zswap_pool_put(entry->pool); if (entry->objcg) { obj_cgroup_uncharge_zswap(entry->objcg, entry->length); obj_cgroup_put(entry->objcg); @@ -1262,11 +1251,6 @@ static unsigned long zswap_shrinker_count(struct shrinker *shrinker, * This ensures that the better zswap compresses memory, the fewer * pages we will evict to swap (as it will otherwise incur IO for * relatively small memory saving). - * - * The memory saving factor calculated here takes same-filled pages into - * account, but those are not freeable since they almost occupy no - * space. Hence, we may scale nr_freeable down a little bit more than we - * should if we have a lot of same-filled pages. */ return mult_frac(nr_freeable, nr_backing, nr_stored); } @@ -1370,42 +1354,6 @@ static void shrink_worker(struct work_struct *w) } while (zswap_total_pages() > thr); } -/********************************* -* same-filled functions -**********************************/ -static bool zswap_is_folio_same_filled(struct folio *folio, unsigned long *value) -{ - unsigned long *data; - unsigned long val; - unsigned int pos, last_pos = PAGE_SIZE / sizeof(*data) - 1; - bool ret = false; - - data = kmap_local_folio(folio, 0); - val = data[0]; - - if (val != data[last_pos]) - goto out; - - for (pos = 1; pos < last_pos; pos++) { - if (val != data[pos]) - goto out; - } - - *value = val; - ret = true; -out: - kunmap_local(data); - return ret; -} - -static void zswap_fill_folio(struct folio *folio, unsigned long value) -{ - unsigned long *data = kmap_local_folio(folio, 0); - - memset_l(data, value, PAGE_SIZE / sizeof(unsigned long)); - kunmap_local(data); -} - /********************************* * main API **********************************/ @@ -1417,7 +1365,6 @@ bool zswap_store(struct folio *folio) struct zswap_entry *entry, *old; struct obj_cgroup *objcg = NULL; struct mem_cgroup *memcg = NULL; - unsigned long value; VM_WARN_ON_ONCE(!folio_test_locked(folio)); VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); @@ -1450,13 +1397,6 @@ bool zswap_store(struct folio *folio) goto reject; } - if (zswap_is_folio_same_filled(folio, &value)) { - entry->length = 0; - entry->value = value; - atomic_inc(&zswap_same_filled_pages); - goto store_entry; - } - /* if entry is successfully added, it keeps the reference */ entry->pool = zswap_pool_current_get(); if (!entry->pool) @@ -1474,7 +1414,6 @@ bool zswap_store(struct folio *folio) if (!zswap_compress(folio, entry)) goto put_pool; -store_entry: entry->swpentry = swp; entry->objcg = objcg; @@ -1522,13 +1461,9 @@ bool zswap_store(struct folio *folio) return true; store_failed: - if (!entry->length) - atomic_dec(&zswap_same_filled_pages); - else { - zpool_free(zswap_find_zpool(entry), entry->handle); + zpool_free(zswap_find_zpool(entry), entry->handle); put_pool: - zswap_pool_put(entry->pool); - } + zswap_pool_put(entry->pool); freepage: zswap_entry_cache_free(entry); reject: @@ -1577,10 +1512,7 @@ bool zswap_load(struct folio *folio) if (!entry) return false; - if (entry->length) - zswap_decompress(entry, folio); - else - zswap_fill_folio(folio, entry->value); + zswap_decompress(entry, folio); count_vm_event(ZSWPIN); if (entry->objcg) @@ -1682,8 +1614,6 @@ static int zswap_debugfs_init(void) zswap_debugfs_root, NULL, &total_size_fops); debugfs_create_atomic_t("stored_pages", 0444, zswap_debugfs_root, &zswap_stored_pages); - debugfs_create_atomic_t("same_filled_pages", 0444, - zswap_debugfs_root, &zswap_same_filled_pages); return 0; }