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 79E6AC433F5 for ; Mon, 10 Jan 2022 15:14:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 022016B0073; Mon, 10 Jan 2022 10:14:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F12F16B0074; Mon, 10 Jan 2022 10:14:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DDB1D6B0075; Mon, 10 Jan 2022 10:14:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0084.hostedemail.com [216.40.44.84]) by kanga.kvack.org (Postfix) with ESMTP id CFFEE6B0073 for ; Mon, 10 Jan 2022 10:14:55 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 7FCD38248D52 for ; Mon, 10 Jan 2022 15:14:55 +0000 (UTC) X-FDA: 79014724950.02.3843D70 Received: from alexa-out-sd-02.qualcomm.com (alexa-out-sd-02.qualcomm.com [199.106.114.39]) by imf19.hostedemail.com (Postfix) with ESMTP id AE6401A0005 for ; Mon, 10 Jan 2022 15:14:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1641827694; x=1673363694; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=jAhOPW5TggcXrIDEgv1JvMUjotEvBmws9U1O6rH07Ng=; b=dFV7WbC5EUMisOhzNbhsdXxL9mfL19ffZhZqJGuy/te2CPNIdAix90vQ wM9SSuOl+ntos9Cb/4ZIPD1CVgFF+jIzu6+NIdHJn1hBA4RD15E3BmAWB 83NGJwNf7BIJM+NVxN1AwQSOC60dgnFjAoeTH+LWwgJR1t/Cx1wq6ajMV E=; Received: from unknown (HELO ironmsg04-sd.qualcomm.com) ([10.53.140.144]) by alexa-out-sd-02.qualcomm.com with ESMTP; 10 Jan 2022 07:14:52 -0800 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg04-sd.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2022 07:14:41 -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.922.19; Mon, 10 Jan 2022 07:14:39 -0800 Received: from [10.216.41.197] (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.922.19; Mon, 10 Jan 2022 07:14:35 -0800 Subject: Re: [PATCH v3 RESEND] mm: shmem: implement POSIX_FADV_[WILL|DONT]NEED for shmem To: Mark Hemment CC: Hugh Dickins , Andrew Morton , "Matthew Wilcox (Oracle)" , , , , "Suren Baghdasaryan" , Shakeel Butt , , , Charan Teja Reddy References: <1641488717-13865-1-git-send-email-quic_charante@quicinc.com> From: Charan Teja Kalla Message-ID: Date: Mon, 10 Jan 2022 20:44:32 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcdkim header.b=dFV7WbC5; spf=pass (imf19.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-Server: rspam06 X-Rspamd-Queue-Id: AE6401A0005 X-Stat-Signature: m17zb55i6qstu1tgefqu19g145cmw7nn X-HE-Tag: 1641827694-638461 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 again Mark for the review comments!! On 1/10/2022 6:06 PM, Mark Hemment wrote: > On Thu, 6 Jan 2022 at 17:06, Charan Teja Reddy > wrote: >> >> From: Charan Teja Reddy >> >> Currently fadvise(2) is supported only for the files that doesn't >> associated with noop_backing_dev_info thus for the files, like shmem, >> fadvise results into NOP. But then there is file_operations->fadvise() >> that lets the file systems to implement their own fadvise >> implementation. Use this support to implement some of the POSIX_FADV_XXX >> functionality for shmem files. > ... >> +static void shmem_isolate_pages_range(struct address_space *mapping, loff_t start, >> + loff_t end, struct list_head *list) >> +{ >> + XA_STATE(xas, &mapping->i_pages, start); >> + struct page *page; >> + >> + rcu_read_lock(); >> + xas_for_each(&xas, page, end) { >> + if (xas_retry(&xas, page)) >> + continue; >> + if (xa_is_value(page)) >> + continue; >> + if (!get_page_unless_zero(page)) >> + continue; >> + if (isolate_lru_page(page)) >> + continue; > > Need to unwind the get_page on failure to isolate. Will be done. > > Should PageUnevicitable() pages (SHM_LOCK) be skipped? > (That is, does SHM_LOCK override DONTNEED?) Should be skipped. Will be done. > > ... >> +static int shmem_fadvise_dontneed(struct address_space *mapping, loff_t start, >> + loff_t end) >> +{ >> + int ret; >> + struct page *page; >> + LIST_HEAD(list); >> + struct writeback_control wbc = { >> + .sync_mode = WB_SYNC_NONE, >> + .nr_to_write = LONG_MAX, >> + .range_start = 0, >> + .range_end = LLONG_MAX, >> + .for_reclaim = 1, >> + }; >> + >> + if (!shmem_mapping(mapping)) >> + return -EINVAL; >> + >> + if (!total_swap_pages) >> + return 0; >> + >> + lru_add_drain(); >> + shmem_isolate_pages_range(mapping, start, end, &list); >> + >> + while (!list_empty(&list)) { >> + page = lru_to_page(&list); >> + list_del(&page->lru); >> + if (page_mapped(page)) >> + goto keep; >> + if (!trylock_page(page)) >> + goto keep; >> + if (unlikely(PageTransHuge(page))) { >> + if (split_huge_page_to_list(page, &list)) >> + goto keep; >> + } > > I don't know the shmem code and the lifecycle of a shm-page, so > genuine questions; > When the try-lock succeeds, should there be a test for PageWriteback() > (page skipped if true)? Also, does page->mapping need to be tested > for NULL to prevent races with deletion from the page-cache? I failed to envisage it. I should have considered both these conditions here. BTW, I am just thinking about why we shouldn't use reclaim_pages(page_list) function here with an extra set_page_dirty() on a page that is isolated? It just call the shrink_page_list() where all these conditions are properly handled. What is your opinion here? > > ... >> + >> + clear_page_dirty_for_io(page); >> + SetPageReclaim(page); >> + ret = shmem_writepage(page, &wbc); >> + if (ret || PageWriteback(page)) { >> + if (ret) >> + unlock_page(page); >> + goto keep; >> + } >> + >> + if (!PageWriteback(page)) >> + ClearPageReclaim(page); >> + >> + /* >> + * shmem_writepage() place the page in the swapcache. >> + * Delete the page from the swapcache and release the >> + * page. >> + */ >> + __mod_node_page_state(page_pgdat(page), >> + NR_ISOLATED_ANON + page_is_file_lru(page), compound_nr(page)); >> + lock_page(page); >> + delete_from_swap_cache(page); >> + unlock_page(page); >> + put_page(page); >> + continue; >> +keep: >> + putback_lru_page(page); >> + __mod_node_page_state(page_pgdat(page), >> + NR_ISOLATED_ANON + page_is_file_lru(page), compound_nr(page)); >> + } > > The putback_lru_page() drops the last reference hold this code has on > 'page'. Is it safe to use 'page' after dropping this reference? True. Will correct it in the next revision. > > Cheers, > Mark >