From patchwork Wed Nov 23 19:17:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 25147 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2987256wrr; Wed, 23 Nov 2022 11:36:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf5qEy71bJacGpuD7uHjuutNCvMmFweLkPPp/FHshx3TDHc/61LMZhUmJCFh1j57z32fu4dx X-Received: by 2002:a17:90a:930f:b0:218:9107:381b with SMTP id p15-20020a17090a930f00b002189107381bmr25268833pjo.75.1669232170921; Wed, 23 Nov 2022 11:36:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669232170; cv=none; d=google.com; s=arc-20160816; b=OUCeO/VLo0YJc8KR0pw41eZzR/ZfMGe6MK3Zb85jMD0hwQlaBlCyV+skCzb4Ftqg2a EW1bQNZP3vmSFYNHaeYCEJO8bCQfXpWXS7FTIRxI/h3pSUFr50meVNGoqelb3RDQOM0D iFtZA5N97z+11XH2BTdjtVEHQEOEv/5BqGxQWfZs6AwCg1K4tgBZXUPo1zTGPKMzsACV mJrBo/YHTyNHY9iXAbFGRnbN+mSqOngZaQuVTwdk/Vh/n+1bpQ47v7hYxQBtd05+JONZ +FzS9IFDv8/MJTE64/Q69Bxif3KjoH1+BUAt72NAaQFjJBmK8mt7KO5wV1X4Nig2DX7Y rRYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=k0SYvGjxlp7dw6JXDykKNCVFvc4QQ+pWPp2+QDRowV4=; b=tYs5FuooZIDyyi1cCw9QAB3XyMmuYn8KcXEVQi1VmawtZA4dusEVeYWFXMWJWtXACz gbalVV6fRMWcZrwkq2abTCNoLfvVLJ7iQoUtftWnP0S9bn09nU2xOFGYxaRwtqr08I2/ QpepcnhKP8nH1BlEToFCcl8Blm87dLmw6AXwe8TFLOP9hM4up/xq4PpOR70BgA0oaGDZ ELlzTmunfba6XB1qqP7QcBDYmJR4qNWIkYXlGemRa+85ZlvnZjmde338Go3tQRt9xxZ1 H25KxtEnvtUmaV+4AXXOsLKDdsgYPlZxyYtntMUhp75aMNrZSJ7fKO5X/yBE47RbL5dZ u2Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kCBq9Ggu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q17-20020a056a00085100b0056aff71af29si3692080pfk.209.2022.11.23.11.35.58; Wed, 23 Nov 2022 11:36:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=kCBq9Ggu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239880AbiKWTRk (ORCPT + 99 others); Wed, 23 Nov 2022 14:17:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239935AbiKWTRM (ORCPT ); Wed, 23 Nov 2022 14:17:12 -0500 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8C68C72DC for ; Wed, 23 Nov 2022 11:17:06 -0800 (PST) Received: by mail-pl1-x633.google.com with SMTP id k7so17491331pll.6 for ; Wed, 23 Nov 2022 11:17:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=k0SYvGjxlp7dw6JXDykKNCVFvc4QQ+pWPp2+QDRowV4=; b=kCBq9GguWJ4WHhxUlYFsFQb4CIUVrgFiCSAnYUxAlbSR0oxyreDtq45d+AovRSAQ7C 1NfMyR8KF1COiW2lb6pdV5PCD90DcINjoOox+n0IDr9+TodG62OR5Eqh4eEDGMOEt/vH vY7wlXqFnwJbDfamwmH7gEf/kTImVPaA332JgUZ+V87tkLSxrWl93o2BF+pYnMVjxhOh yveVws5/DPVjOIdLKaJ9MMvqpj0NwkgiVBHL4WqWJrVtgNaR87hIIS1+CZjiWf7VTfsW qKr+FFrLJtiv7/xEh3gmT2FvrrWxlJH1VtYA9yOj5yS1Q0N/PIPT6oEa5vCwIfrlpBCF fY/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=k0SYvGjxlp7dw6JXDykKNCVFvc4QQ+pWPp2+QDRowV4=; b=NZY4MBB8X1uQyXTHHOYFJprtJrF9yc/eRfrFSymN6rCY92P/Pu8GuwAkmF+R97NMfZ yyPg2eyGiY9NfhhQmAFKkbil08VkfaqlBQA1S6jkCOxsXEkjeQXtmRODGZzFH9IfhTN2 LdlPODCoopA91yg+q5yqWjzsdCpWonrqOd4BKswNQsffkXYdNPLdpUKl45PAR6YIh4pS sQ3rn9S+9X4PNBsctQj5xOehZ1IhnuF5j5OE612NGSS+h+Hnjd6X5mSIRBqILidyMfU4 x4WJFysvyUnH6agHwghcTVV0HHskuycNWo3QlEwXxNkImeKn1SLQ+RLBoIUpPsB0+sIg JyNA== X-Gm-Message-State: ANoB5pmAQfiAjXEItGLdizbEGUpx3AsLfSVwjwLN2xdHxA77Kjnf2g// sO4dyF8VAlN9y2o6zALCsUk= X-Received: by 2002:a17:902:8f96:b0:189:3803:23e6 with SMTP id z22-20020a1709028f9600b00189380323e6mr7577592plo.77.1669231026347; Wed, 23 Nov 2022 11:17:06 -0800 (PST) Received: from localhost (fwdproxy-prn-020.fbsv.net. [2a03:2880:ff:14::face:b00c]) by smtp.gmail.com with ESMTPSA id l7-20020a170902f68700b00177fb862a87sm14920203plg.20.2022.11.23.11.17.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 11:17:05 -0800 (PST) From: Nhat Pham To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, minchan@kernel.org, ngupta@vflare.org, senozhatsky@chromium.org, sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com Subject: [PATCH v6 4/6] zsmalloc: Add a LRU to zs_pool to keep track of zspages in LRU order (fix) Date: Wed, 23 Nov 2022 11:17:02 -0800 Message-Id: <20221123191703.2902079-2-nphamcs@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221123191703.2902079-1-nphamcs@gmail.com> References: <20221123191703.2902079-1-nphamcs@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750316792472558119?= X-GMAIL-MSGID: =?utf-8?q?1750316792472558119?= Add a comment explaining the mapping check for LRU update. Signed-off-by: Nhat Pham Suggested-by: Johannes Weiner Suggested-by: Sergey Senozhatsky --- mm/zsmalloc.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) -- 2.30.2 diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 7dd464b5a6a5..d9bd865047e2 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -1268,7 +1268,23 @@ void *zs_map_object(struct zs_pool *pool, unsigned long handle, zspage = get_zspage(page); #ifdef CONFIG_ZPOOL - /* Move the zspage to front of pool's LRU */ + /* + * Move the zspage to front of pool's LRU. + * + * Note that this is swap-specific, so by definition there are no ongoing + * accesses to the memory while the page is swapped out that would make + * it "hot". A new entry is hot, then ages to the tail until it gets either + * written back or swaps back in. + * + * Furthermore, map is also called during writeback. We must not put an + * isolated page on the LRU mid-reclaim. + * + * As a result, only update the LRU when the page is mapped for write + * when it's first instantiated. + * + * This is a deviation from the other backends, which perform this update + * in the allocation function (zbud_alloc, z3fold_alloc). + */ if (mm == ZS_MM_WO) { if (!list_empty(&zspage->lru)) list_del(&zspage->lru); From patchwork Wed Nov 23 19:17:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 25146 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2987182wrr; Wed, 23 Nov 2022 11:36:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf7WMzuUnpbClb2l8di3siHFPpBQ9AXMpylhQt8u2UmpZGegiAit16i9kqoV2ouQCmSY5RV1 X-Received: by 2002:a17:90a:2f23:b0:218:72e0:307b with SMTP id s32-20020a17090a2f2300b0021872e0307bmr31800957pjd.183.1669232160815; Wed, 23 Nov 2022 11:36:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669232160; cv=none; d=google.com; s=arc-20160816; b=dcSyTCEjZUbQCwftcaZjSurrPx6ZNul8PDgnDYqq6/ccOGlHC+pwU+TCgoaR3es49s gaWINZ4EAVOgHWIuuJIGgcvaTnrfp0Xrq9FiKERXHVUg/Ag4hOHgvxe9wKLpAGheDNer sJ50ng49AVm9+jCSd+9bZZ195SIHSwnW5NFZS5TVqu/Jtd0PVLq3vvLDWKVeNc8SV8IJ 4PlrkFaLmDpzfqEg1TWES8YXdWMeO6SS31ubWT5QXSBQ7gxiGP/s1dQymR8GXuAVVdS+ WvCJ2afpnXKrabiBr+9HytiSM3Z3XAL0vWAuqoNaQ+61b6n0NUKsPY6CQ+tH9rwHTVmN ArAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ruO+YinHt02cD7LDLng29WAK5pZvQbCFBqvYCl3hrTY=; b=iQMcNnmLJUo4AJov8KIgk4PVQytbJFuco1gG+0Uni1GXgoXdUuZC1HuQHGUw5k/Swe wuh4+D8YSBWcAS9nQsPxgbbgZTqGLJ4k8znDV4/fSVNghg/uLfRvtEHIh743TvlgUPFQ f9H1lu+P3caG6hWVDOeKcjtpiNUn2TXdxCCqAMjda7FYv00knPeqsAB/TDN7uCznd9Zf VpOVeWFnjvrUat7eWccvrXJ2pDHqOGoz+VX956djdBuCGiTxz9/YgRPcnwrfaUyaVIb8 98OusuTRQBFdGITeGNQx5+ue4U99VKZaQa7WnGrPVlHWkUUjpZEl3rfs+5/khacGtjKm hqXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ixSC8hDn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j13-20020a056a00174d00b0056dc342ea54si18269262pfc.206.2022.11.23.11.35.48; Wed, 23 Nov 2022 11:36:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ixSC8hDn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237702AbiKWTRh (ORCPT + 99 others); Wed, 23 Nov 2022 14:17:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239936AbiKWTRM (ORCPT ); Wed, 23 Nov 2022 14:17:12 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BF83C78FC for ; Wed, 23 Nov 2022 11:17:08 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id v3-20020a17090ac90300b00218441ac0f6so4320156pjt.0 for ; Wed, 23 Nov 2022 11:17:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=ruO+YinHt02cD7LDLng29WAK5pZvQbCFBqvYCl3hrTY=; b=ixSC8hDnbztU0OC/soKUCSkVcuZpNhHZrTMy73xNCHzzfaOyQag8wcAC0zxDGxBQEL cFv7auDe3Fi4p541vWWnL5tcLNc4ebxoGg0/B1hK8LUhXQmzZgDYmUKupPy06uvdhq+u pZ/qgHC8iO7qPQHIiBSf2jxM95OSvjRzimzrdE/EZR2Fz8kS07wolWVCu7u8UnPTSxL/ 8f96Cj1m0EalvWOY5NWkL9XLuCj8AWz+EPKHmBSSQ4uS1ymXh/gwxuCrYA0BxUh72CNF w9kAwhEjdjC6kPN96wiobHFCgI++KuKuykXndt6lKhDz6zmY/05z3P/IVvnwBJCzZpMr yocA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=ruO+YinHt02cD7LDLng29WAK5pZvQbCFBqvYCl3hrTY=; b=K8Z3i6nwYPdnAU6SUJR1F0ZhjuQeGlnC/wwg9dzkU+QS8jYhf42SLt2/LglkpVgIii sVbGuEOtCTAGTdYbsAUjM0QBcuyanzWJGd4Vu6L/oakY2CoB/WkSYNFfj5mHF/d2ac3L kRc09nWYAT2UEexWkC55gdaHP1fa0j+r1YoMPLpf44i2wcaT2G4KUyXtnPGj0qpMuuvH ZGpX4NgUCaeUsk+39laH/xKDcQTIZtfbDsRRkSHbkJ9okO2PQazFF0ov7TSVbxdswZmk kCTr0dfFPvSYbrThfj++rRm1CN2Uq0WlJ2GNqN1sj/nH/zy8fJKre9ftzTNt8Cdm4U9o QPww== X-Gm-Message-State: ANoB5pmL5i2OKCEK9KS4jIWDu1PXE+tY25OOv/LtbCnNNJjUAqsU5eUg Z2MnfjWijKMhoazDBnBrkgc= X-Received: by 2002:a17:902:ab1d:b0:188:f5de:a8e4 with SMTP id ik29-20020a170902ab1d00b00188f5dea8e4mr11050853plb.133.1669231027538; Wed, 23 Nov 2022 11:17:07 -0800 (PST) Received: from localhost (fwdproxy-prn-020.fbsv.net. [2a03:2880:ff:14::face:b00c]) by smtp.gmail.com with ESMTPSA id a4-20020a170902ecc400b00180a7ff78ccsm14790814plh.126.2022.11.23.11.17.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 11:17:07 -0800 (PST) From: Nhat Pham To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, minchan@kernel.org, ngupta@vflare.org, senozhatsky@chromium.org, sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com Subject: [PATCH v6 6/6] zsmalloc: Implement writeback mechanism for zsmalloc (fix) Date: Wed, 23 Nov 2022 11:17:03 -0800 Message-Id: <20221123191703.2902079-3-nphamcs@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221123191703.2902079-1-nphamcs@gmail.com> References: <20221123191703.2902079-1-nphamcs@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750316782429107764?= X-GMAIL-MSGID: =?utf-8?q?1750316782429107764?= Use get_first_page(), and add cond_resched() in retry loop. Signed-off-by: Nhat Pham Suggested-by: Sergey Senozhatsky --- mm/zsmalloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.30.2 diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index e2bd41f37b5b..ab4fa17a0fad 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -2488,12 +2488,13 @@ static int zs_reclaim_page(struct zs_pool *pool, unsigned int retries) remove_zspage(class, zspage, fullness); spin_unlock(&pool->lock); + cond_resched(); /* Lock backing pages into place */ lock_zspage(zspage); obj_idx = 0; - page = zspage->first_page; + page = get_first_page(zspage); while (1) { handle = find_alloced_obj(class, page, &obj_idx); if (!handle) {