From mboxrd@z Thu Jan 1 00:00:00 1970 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 78FDBC433F5 for ; Mon, 7 Mar 2022 14:50:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED46D8D0002; Mon, 7 Mar 2022 09:50:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E833B8D0001; Mon, 7 Mar 2022 09:50:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D24398D0002; Mon, 7 Mar 2022 09:50:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id BC7EF8D0001 for ; Mon, 7 Mar 2022 09:50:37 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8AF1823CD8 for ; Mon, 7 Mar 2022 14:50:37 +0000 (UTC) X-FDA: 79217876514.13.D3C2AB6 Received: from alexa-out-sd-02.qualcomm.com (alexa-out-sd-02.qualcomm.com [199.106.114.39]) by imf21.hostedemail.com (Postfix) with ESMTP id BEBA01C000A for ; Mon, 7 Mar 2022 14:50:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1646664636; x=1678200636; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=g3MS51Wrb/eQYTnuO0rlbMIdHyQkKGH4tCbFKOZOOtc=; b=EOy7hqjFUFwJVbD7nOUM2YtVnYEBaqcUg6lnGgtqACG9K1FcaKhrmHcW Vw/hsCMjRnNHXLNkBHDb1Icu07F7c8xOpNUA89B5i5VNbVIBlZr+Z8wFq oYRjcaawewPO6kCljOJ9+WatjnlvwRFBGkii9+MPGzfKeahNYlc8ElKa6 g=; Received: from unknown (HELO ironmsg03-sd.qualcomm.com) ([10.53.140.143]) by alexa-out-sd-02.qualcomm.com with ESMTP; 07 Mar 2022 06:50:35 -0800 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg03-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Mar 2022 06:50:35 -0800 Received: from nalasex01a.na.qualcomm.com (10.47.209.196) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.15; Mon, 7 Mar 2022 06:50:34 -0800 Received: from [10.216.62.152] (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.15; Mon, 7 Mar 2022 06:50:30 -0800 Message-ID: Date: Mon, 7 Mar 2022 20:20:27 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.0 Subject: Re: [PATCH v4] mm: shmem: implement POSIX_FADV_[WILL|DONT]NEED for shmem Content-Language: en-US To: Suren Baghdasaryan CC: Hugh Dickins , Andrew Morton , Matthew Wilcox , , Vlastimil Babka , David Rientjes , Michal Hocko , Shakeel Butt , linux-mm , LKML References: <1644572051-24091-1-git-send-email-quic_charante@quicinc.com> From: Charan Teja Kalla In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01a.na.qualcomm.com (10.47.209.196) X-Rspamd-Server: rspam10 X-Rspam-User: X-Stat-Signature: shimuq51qj83g7xs3mr1fkrmrxpju5yk Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcdkim header.b=EOy7hqjF; spf=pass (imf21.hostedemail.com: domain of quic_charante@quicinc.com designates 199.106.114.39 as permitted sender) smtp.mailfrom=quic_charante@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com X-Rspamd-Queue-Id: BEBA01C000A X-HE-Tag: 1646664636-195506 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: Thanks Suren for your comments!! On 3/5/2022 2:00 AM, Suren Baghdasaryan wrote: >> + test_and_clear_page_young(page); >> + SetPageDirty(page); > I asked Hugh about how clean shmem pages are handled during normal > reclaim and his reply is: > > Clean shmem pages are rare: they correspond to where a hole in a > sparse file has been mapped read-only to userspace. Those get dropped > from pagecache without being written to swap, when memory pressure > comes to reclaim them. Otherwise, shmem pages are dirty: as soon as > they've been read from swap and identified as shmem (moved from swap > cache to page cache), that swap is freed so they're no longer clean > representations of anything on swap. (Our use of "swap cache" and/or > "page cache" may have inconsistencies in what I've written: sometimes > we use them interchangeably, sometimes we're making a distinction.) > > So, IIUC his explanation, you don't really need to mark clean shmem > pages dirty for FADV_DONTNEED since normal reclaim does not do that > either. Thanks for the details here. Will change it in the next patch. > >> + list_add(&page->lru, list); >> + if (need_resched()) { >> + xas_pause(&xas); >> + cond_resched_rcu(); >> + } >> + } >> + rcu_read_unlock(); >> +} >> + >> +static int shmem_fadvise_dontneed(struct address_space *mapping, loff_t start, >> + loff_t end) >> +{ >> + LIST_HEAD(list); >> + >> + if (!shmem_mapping(mapping)) >> + return -EINVAL; >> + >> + if (!total_swap_pages) >> + return 0; >> + >> + lru_add_drain(); >> + shmem_isolate_pages_range(mapping, start, end, &list); >> + reclaim_pages(&list); >> + >> + return 0; >> +} >> + >> +static int shmem_fadvise_willneed(struct address_space *mapping, >> + pgoff_t start, pgoff_t long end) >> +{ >> + struct page *page; >> + pgoff_t index; >> + >> + xa_for_each_range(&mapping->i_pages, index, page, start, end) { >> + if (!xa_is_value(page)) >> + continue; >> + page = shmem_read_mapping_page(mapping, index); >> + if (!IS_ERR(page)) >> + put_page(page); >> + } >> + >> + return 0; >> +} >> + >> +static int shmem_fadvise(struct file *file, loff_t offset, loff_t len, int advice) >> +{ >> + loff_t endbyte; >> + pgoff_t start_index;. >> + pgoff_t end_index; >> + struct address_space *mapping; >> + int ret = 0; >> + >> + mapping = file->f_mapping; >> + if (!mapping || len < 0) >> + return -EINVAL; >> + >> + endbyte = (u64)offset + (u64)len; >> + if (!len || endbyte < len) >> + endbyte = -1; >> + else >> + endbyte--; > The above block is exactly the same as in > https://elixir.bootlin.com/linux/latest/source/mm/fadvise.c#L73 with > the exception that generic_fadvise has comments with explanations of > this math. You might consider consolidating them into a helper > function to calculate the endbyte. Yes, I simply copy pasted these. Will try to consolidate them into one. >