From patchwork Tue May 11 12:54:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruben Bremer X-Patchwork-Id: 12250869 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B579C433ED for ; Tue, 11 May 2021 12:55:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C809961921 for ; Tue, 11 May 2021 12:54:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C809961921 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=mail.ee Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3F6F36B0071; Tue, 11 May 2021 08:54:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CCDF6B0072; Tue, 11 May 2021 08:54:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 26ED18D0002; Tue, 11 May 2021 08:54:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0051.hostedemail.com [216.40.44.51]) by kanga.kvack.org (Postfix) with ESMTP id 0B4A86B0071 for ; Tue, 11 May 2021 08:54:59 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id BEF828249980 for ; Tue, 11 May 2021 12:54:58 +0000 (UTC) X-FDA: 78128945076.10.A541043 Received: from eu-shark2.inbox.eu (eu-shark2.inbox.eu [195.216.236.82]) by imf27.hostedemail.com (Postfix) with ESMTP id A9BF98019380 for ; Tue, 11 May 2021 12:54:56 +0000 (UTC) Received: from eu-shark2.inbox.eu (localhost [127.0.0.1]) by eu-shark2-out.inbox.eu (Postfix) with ESMTP id 7264B1E00724; Tue, 11 May 2021 15:54:55 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mail.ee; s=20150108; t=1620737695; bh=hA2OSosjWLjyAtiYEXr3cpU0VHpPrCouar+UdM8Vghg=; h=To:Cc:From:Subject:Date; b=jOHX7FTF2X/tdTqr8PNqfP0UzLXyyOQNCyHwm3Pdd0bm42W8pFI3HVdGcPkLNeAJn Hx8HoHVWOmW7OMfQrm/4wz0PedP7kXBht3LrphspnhDpn6kF+Y2bYhKjNvVZ1J6qdA F6YkRT/0oEuESZp2YEptHELdGgOG80tqFbSpZ/sI= Received: from localhost (localhost [127.0.0.1]) by eu-shark2-in.inbox.eu (Postfix) with ESMTP id 692E01E0071E; Tue, 11 May 2021 15:54:55 +0300 (EEST) Received: from eu-shark2.inbox.eu ([127.0.0.1]) by localhost (eu-shark2.inbox.eu [127.0.0.1]) (spamfilter, port 35) with ESMTP id 8ZzHaaApifug; Tue, 11 May 2021 15:54:55 +0300 (EEST) Received: from mail.inbox.eu (eu-pop1 [127.0.0.1]) by eu-shark2-in.inbox.eu (Postfix) with ESMTP id 1D6871E006CF; Tue, 11 May 2021 15:54:55 +0300 (EEST) Received: from linux.fritz.box (unknown [212.21.66.6]) (Authenticated sender: rb@mail.ee) by mail.inbox.eu (Postfix) with ESMTPA id 6DEA91BE007D; Tue, 11 May 2021 15:54:52 +0300 (EEST) To: Seth Jennings , Dan Streetman , Vitaly Wool , linux-mm@kvack.org Cc: rb@mail.ee From: Ruben Bremer Subject: [PATCH] mm/zswap.c: avoid partial LRU inversion by evicting pages earlier Message-ID: <43912f1a-c607-ff55-50c7-3285cfb5e7c0@mail.ee> Date: Tue, 11 May 2021 14:54:47 +0200 MIME-Version: 1.0 Content-Language: en-US X-Virus-Scanned: OK X-ESPOL: +dBm1NUOBkfEh1ygQWXcBBgxqTRPQJ6W9pa7zH8qkX7mU1qJf04MWBewlW1xSmA= X-Rspamd-Queue-Id: A9BF98019380 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=mail.ee header.s=20150108 header.b=jOHX7FTF; spf=pass (imf27.hostedemail.com: domain of rb@mail.ee designates 195.216.236.82 as permitted sender) smtp.mailfrom=rb@mail.ee; dmarc=pass (policy=quarantine) header.from=mail.ee X-Rspamd-Server: rspam04 X-Stat-Signature: 86o93mt46cqy9m41kjs1g66it93iy9fm Received-SPF: none (mail.ee>: No applicable sender policy available) receiver=imf27; identity=mailfrom; envelope-from=""; helo=eu-shark2.inbox.eu; client-ip=195.216.236.82 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620737696-866158 X-Bogosity: Ham, tests=bogofilter, spamicity=0.008120, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Zswap can evict stored pages on an LRU basis when its pool is full. However, new incoming pages will then simultaneously also be rejected and thus sent directly to swap, thereby effectively partially inversing LRU caching behavior. In order to avoid this LRU inversion, this patch allows zswap to begin evicting pages earlier when its pool is only 90 % full but still accept new incoming pages. There may be more elegant solutions. --- a/mm/zswap.c~mm-zswap-avoid-lru-inversion-by-earlier-eviction +++ a/mm/zswap.c @@ -228,6 +228,12 @@ static const struct zpool_ops zswap_zpoo .evict = zswap_writeback_entry }; +static bool zswap_is_almost_full(void) +{ + return totalram_pages() * zswap_max_pool_percent / 111 < + DIV_ROUND_UP(zswap_pool_total_size, PAGE_SIZE); +} + static bool zswap_is_full(void) { return totalram_pages() * zswap_max_pool_percent / 100 < @@ -1109,20 +1115,24 @@ static int zswap_frontswap_store(unsigne } /* reclaim space if needed */ - if (zswap_is_full()) { + if (zswap_is_almost_full()) { struct zswap_pool *pool; - zswap_pool_limit_hit++; - zswap_pool_reached_full = true; pool = zswap_pool_last_get(); - if (pool) + if (pool) { queue_work(shrink_wq, &pool->shrink_work); - ret = -ENOMEM; - goto reject; + } + + if (zswap_is_full()) { + zswap_pool_limit_hit++; + zswap_pool_reached_full = true; + ret = -ENOMEM; + goto reject; + } } if (zswap_pool_reached_full) { - if (!zswap_can_accept()) { + if (!zswap_can_accept()) { ret = -ENOMEM; goto reject; } else