From patchwork Mon Oct 10 11:00:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaoyang.huang" X-Patchwork-Id: 13002477 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 7CC9CC4332F for ; Mon, 10 Oct 2022 11:01:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1AD396B0071; Mon, 10 Oct 2022 07:01:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 135556B0073; Mon, 10 Oct 2022 07:01:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3F4D6B0074; Mon, 10 Oct 2022 07:01:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E12F76B0071 for ; Mon, 10 Oct 2022 07:01:38 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9CBAC120E29 for ; Mon, 10 Oct 2022 11:01:38 +0000 (UTC) X-FDA: 80004749076.29.D6C49F9 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) by imf29.hostedemail.com (Postfix) with ESMTP id 31F4E12002B for ; Mon, 10 Oct 2022 11:01:35 +0000 (UTC) Received: from SHSend.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by SHSQR01.spreadtrum.com with ESMTPS id 29AB0i36074609 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NO); Mon, 10 Oct 2022 19:00:45 +0800 (CST) (envelope-from zhaoyang.huang@unisoc.com) Received: from bj03382pcu.spreadtrum.com (10.0.74.65) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 10 Oct 2022 19:00:44 +0800 From: "zhaoyang.huang" To: Andrew Morton , Matthew Wilcox , Vlastimil Babka , Zhaoyang Huang , , , , , Subject: [RFC PATCH] mm: skip GFP_IO if swap is zram only Date: Mon, 10 Oct 2022 19:00:22 +0800 Message-ID: <1665399622-20236-1-git-send-email-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.0.74.65] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 29AB0i36074609 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665399697; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references; bh=uGPrqdP5eblPr5yn/GvkN52yZQm3S8ZqSziPi/M/yzM=; b=piG/1KwQjq0Rus8WRtzcJlNEP6Zw6knZZ/TAx1Q1OO6Czle9gxPvP9iux0LgDPrdnS5TA/ y6f0+hlb6nI1Z70HuX+0d49jpSA9UzU5PvHCz9DqD9CVxX4gwQ/ycUuafMJl2cYYk8+VVJ Ys8FQAR+ejgWM1bBxtZ2k2hELTap3as= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665399697; a=rsa-sha256; cv=none; b=zUQcc8Yuap3+B/kPAWHzoO6n+5DY7phxWdgdwl4ldrm0CVlxQ8lhXiDdXwdjJLvxcRQeSU TR1v3cpda/K5TNWNGTZxH5IUHh+CV1mhyhk+xARyPLl8qwPF9eq8gfk5laOjDw8TUohOCm 3T+PW0j7f0etpgLchkFEtDu50uzM14c= Authentication-Results: imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of zhaoyang.huang@unisoc.com designates 222.66.158.135 as permitted sender) smtp.mailfrom=zhaoyang.huang@unisoc.com; dmarc=none X-Rspam-User: X-Stat-Signature: zmkg3byukz4y6skrxh78snyp4tgkrjqh X-Rspamd-Queue-Id: 31F4E12002B X-Rspamd-Server: rspam01 X-HE-Tag: 1665399695-669564 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: From: Zhaoyang Huang __GFP_IO is believed to prevent the allocation being suspended due to accessing physical block devices when reclaiming dirty pages. Zram is not considered as such kind of device from kernel perspective of view. Do swap things if the system is zram only. Signed-off-by: Zhaoyang Huang --- include/linux/swap.h | 1 + include/linux/swapfile.h | 1 - mm/swapfile.c | 7 +++++++ mm/vmscan.c | 3 ++- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 43150b9..c160b2e 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -505,6 +505,7 @@ static inline long get_nr_swap_pages(void) extern int init_swap_address_space(unsigned int type, unsigned long nr_pages); extern void exit_swap_address_space(unsigned int type); extern struct swap_info_struct *get_swap_device(swp_entry_t entry); +extern bool if_swap_zram_only(void); sector_t swap_page_sector(struct page *page); static inline void put_swap_device(struct swap_info_struct *si) diff --git a/include/linux/swapfile.h b/include/linux/swapfile.h index 5407854..e229c36 100644 --- a/include/linux/swapfile.h +++ b/include/linux/swapfile.h @@ -9,5 +9,4 @@ extern struct swap_info_struct *swap_info[]; extern unsigned long generic_max_swapfile_size(void); extern unsigned long max_swapfile_size(void); - #endif /* _LINUX_SWAPFILE_H */ diff --git a/mm/swapfile.c b/mm/swapfile.c index 1fdccd2..e1b2969 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3663,6 +3663,13 @@ void __cgroup_throttle_swaprate(struct page *page, gfp_t gfp_mask) } #endif +bool if_swap_zram_only(void) +{ + return ((nr_swapfiles == 1) + && !strncmp(swap_info[0]->bdev->bd_disk->disk_name, "zram", 4)); +} +EXPORT_SYMBOL_GPL(if_swap_zram_only); + static int __init swapfile_init(void) { int nid; diff --git a/mm/vmscan.c b/mm/vmscan.c index b2b1431..37500b5 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1770,7 +1770,8 @@ static unsigned int shrink_page_list(struct list_head *page_list, */ if (folio_test_anon(folio) && folio_test_swapbacked(folio)) { if (!folio_test_swapcache(folio)) { - if (!(sc->gfp_mask & __GFP_IO)) + if (!(sc->gfp_mask & __GFP_IO) + && !if_swap_zram_only()) goto keep_locked; if (folio_maybe_dma_pinned(folio)) goto keep_locked;