Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp856452pxa; Wed, 19 Aug 2020 17:29:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAWa5bZ4nHLL/6IvATXUjCJvtkJZNbziXrJp6Wt2aMfk9Da+TgyuXRVLfeYIZt1brxkrBW X-Received: by 2002:a17:907:7292:: with SMTP id dt18mr880202ejc.512.1597883379707; Wed, 19 Aug 2020 17:29:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597883379; cv=none; d=google.com; s=arc-20160816; b=kEJ59f1zM8iqE/1aKENMejmMULLitkcctPHS6EqtOx79bjsOG54gbMj4QF8BDAqw9J JVmuE5aUBt/fWVOVDERlG/9iVauOg1yDaYO/picUpoXWYcM3NjTxjqmzEJBPg+Yl4iXA ZMIgA8AIBvUjxTRR3NXYfyR6brRQBakLyjD3Uw810/IRpMPO9zcQ8pl3rb9nO6ovbsaQ nMiwaBNthdgFcY4jywQ9Q8UAcB21ybNjCNe8L1kk3MUrr4jB/Atcv3Lx/DmjmMv+ngpI r2E+RcuI8kXK4RG2Uk8NtqwqQbCbHFqL5NXpK2+Q4hyrsGOHwEy9qZ39rtFnpj7gAfZ6 S3rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=mE4zqw7ry1MfZH9x184nZ2vzhA0MYzok+VpmlWA+zfk=; b=gU29aVc1CR6q3nKMd8fFSN3OtMLdz+VMcXsjMHBsYQpV+5LDFUlaes57e3kD3B2QVG c4lBmgcu0dfTqR5itEbMgSaQByxZY/jclK90hfOsRLazNEE9ucU1i6tr5/1czQYJLfFU NSfN13pjwrAqde5CPEHRfqcCnOtMLYliZR8zKLoBKAEXvu2lgXdDRFrscKRGNoyMrYWu 4Xjn4+YcmUTYdwEn463elIn4JwXCEfJRGSxO8KkL4KadvxJX9Jv2XVEGYDbwMN79SH/L zg9XKtjfw4cimmC8VjEcWSJvT+FcHNoPiaRj4T+4ERi2RCOiAHzobfgSpPSyoRvG6IJo HYuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gHcwkVEn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c22si345756edr.146.2020.08.19.17.29.13; Wed, 19 Aug 2020 17:29:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gHcwkVEn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726749AbgHTA0c (ORCPT + 99 others); Wed, 19 Aug 2020 20:26:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726617AbgHTA0b (ORCPT ); Wed, 19 Aug 2020 20:26:31 -0400 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C842C061383 for ; Wed, 19 Aug 2020 17:26:29 -0700 (PDT) Received: by mail-lf1-x142.google.com with SMTP id j15so80060lfg.7 for ; Wed, 19 Aug 2020 17:26:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mE4zqw7ry1MfZH9x184nZ2vzhA0MYzok+VpmlWA+zfk=; b=gHcwkVEnunAcNAqPlLjtg0pSC0LdqrIfnZYk/Ajg6bM6EpGoCa/IaA4IjPsMfKhIE2 DWR+LcqK6o1msWSHL7lEADWCyseNQlRdVCWfqN16VTR+v3gg5NnBEhWkUAZEm9+vcnBN kubQnJ9KgFgT16G53OTR2T+kS+H1xRWRUd/u9OZxqTCNFZYNrGprPlDtXKwcZ/9IJHGg lug2//c6ZgN2mQ5eOHUW5mGeUDmw3ZLKKJzuY8Qn0teavWO/or7bsADvVdHKt5vYi2tu ExPBGB8SM56GfFnMXpuzbGH91OapxDb+0b+lTlWPbU/5bQ3t2jRofUPbxva/5kUr4xRC fK8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mE4zqw7ry1MfZH9x184nZ2vzhA0MYzok+VpmlWA+zfk=; b=j3BO9GM95TpfzoMHf7x0e60mFokayW8GNrXEemcOFXvIdW7m0P+8rq/DjDUc2lbA7F yuBOOfhX2IqnreChYEsJxfpsnfzc5sp5efhuGwCxD0udQunGmAIL8tK/JOTnzqsEIJwm 3tC/4qi2sK6sUSzqu9V6WDHZPM8NxowqDcduF22NX5zfFdExR5Nuq+8fgLpRsEccpEeV JIBljlQTO5YGsXsP2Qk4wY52KcGpTHHLQkq5hobzl4noFbdWIByAONgRvGKqH0j9s8UF YRbZQQfzUalDPYmrGK0Ig0nVNE0w/BN1YdHEfGWhinsWW/8h0LrutHkl+ifsBuo8qUAm NJKA== X-Gm-Message-State: AOAM5324eeET6TcJynOXvogLpl4F0BDi8rkApxRjU4EJMtH2PsPHDlKB amYm3yKqTkIULR76OcKjw88UqLwT2R2+53S8m4zsJw== X-Received: by 2002:a19:c68b:: with SMTP id w133mr284468lff.189.1597883187523; Wed, 19 Aug 2020 17:26:27 -0700 (PDT) MIME-Version: 1.0 References: <20200818072501.30396-1-sjpark@amazon.com> <20200818072501.30396-7-sjpark@amazon.com> In-Reply-To: <20200818072501.30396-7-sjpark@amazon.com> From: Shakeel Butt Date: Wed, 19 Aug 2020 17:26:15 -0700 Message-ID: Subject: Re: [RFC v7 06/10] mm/damon: Implement callbacks for physical memory monitoring To: SeongJae Park Cc: Andrew Morton , SeongJae Park , Jonathan.Cameron@huawei.com, Andrea Arcangeli , acme@kernel.org, alexander.shishkin@linux.intel.com, amit@kernel.org, benh@kernel.crashing.org, brendan.d.gregg@gmail.com, Brendan Higgins , Qian Cai , Colin Ian King , Jonathan Corbet , David Hildenbrand , dwmw@amazon.com, "Du, Fan" , foersleo@amazon.de, Greg Thelen , Ian Rogers , jolsa@redhat.com, "Kirill A. Shutemov" , mark.rutland@arm.com, Mel Gorman , Minchan Kim , Ingo Molnar , namhyung@kernel.org, "Peter Zijlstra (Intel)" , Randy Dunlap , Rik van Riel , David Rientjes , Steven Rostedt , rppt@kernel.org, sblbir@amazon.com, shuah@kernel.org, sj38.park@gmail.com, snu@amazon.de, Vlastimil Babka , Vladimir Davydov , Yang Shi , Huang Ying , zgf574564920@gmail.com, linux-damon@amazon.com, Linux MM , linux-doc@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 18, 2020 at 12:27 AM SeongJae Park wrote: > > From: SeongJae Park > > This commit implements the four callbacks (->init_target_regions, > ->update_target_regions, ->prepare_access_check, and ->check_accesses) > for the basic access monitoring of the physical memory address space. > By setting the callback pointers to point those, users can easily > monitor the accesses to the physical memory. > > Internally, it uses the PTE Accessed bit, as similar to that of the > virtual memory support. Also, it supports only user memory pages, as > idle page tracking also does, for the same reason. If the monitoring > target physical memory address range contains non-user memory pages, > access check of the pages will do nothing but simply treat the pages as > not accessed. > > Users who want to use other access check primitives and/or monitor the > non-user memory regions could implement and use their own callbacks. > > Signed-off-by: SeongJae Park [snip] > +static void damon_phys_mkold(unsigned long paddr) > +{ > + struct page *page = damon_phys_get_page(PHYS_PFN(paddr)); > + struct rmap_walk_control rwc = { > + .rmap_one = damon_page_mkold, > + .anon_lock = page_lock_anon_vma_read, > + }; > + bool need_lock; > + > + if (!page) > + return; > + > + if (!page_mapped(page) || !page_rmapping(page)) > + return; I don't think you want to skip the unmapped pages. The point of physical address space monitoring was to include the monitoring of unmapped pages, so, skipping them invalidates the underlying motivation. > + > + need_lock = !PageAnon(page) || PageKsm(page); > + if (need_lock && !trylock_page(page)) > + return; > + > + rmap_walk(page, &rwc); > + > + if (need_lock) > + unlock_page(page); > + put_page(page); > +} > + [snip] > + > +static bool damon_phys_young(unsigned long paddr, unsigned long *page_sz) > +{ > + struct page *page = damon_phys_get_page(PHYS_PFN(paddr)); > + struct damon_phys_access_chk_result result = { > + .page_sz = PAGE_SIZE, > + .accessed = false, > + }; > + struct rmap_walk_control rwc = { > + .arg = &result, > + .rmap_one = damon_page_accessed, > + .anon_lock = page_lock_anon_vma_read, > + }; > + bool need_lock; > + > + if (!page) > + return false; > + > + if (!page_mapped(page) || !page_rmapping(page)) > + return false; Same here. > + > + need_lock = !PageAnon(page) || PageKsm(page); > + if (need_lock && !trylock_page(page)) > + return false; > + > + rmap_walk(page, &rwc); > + > + if (need_lock) > + unlock_page(page); > + put_page(page); > + > + *page_sz = result.page_sz; > + return result.accessed; > +} > +