From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B1B693B9952 for ; Wed, 26 Aug 2026 10:24:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787739847; cv=none; b=Je73L8LxiJC8uv8CTHwlC44cIBr6aClVFlSwE3n7YNv43atCRrZhZpG1zrm45Y6aXDaIWimdegB2meI/iNi/Z5KuaqdE8dcwAGIAcehVMRFgF5SHxuDgNNS6+K2VToPoXOr6i4MGvWY0Y7bmQx1QMGPLhJz3uOZ1Ud+2b2/PpGo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787739847; c=relaxed/simple; bh=RUq1wR4ZMkqZ3vbE7MBsWYz5ukgX1zWXwxhMjIhQDTE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=boMukhM8XSvbrsXpF72+WZcOAZMOl9DwDGPhs+9cBQmweQRWU/urYIJSCxvnvjEKP5c023ONKc+bDla31jhowssITc4VwAEUI9x61wFtdjlIZuZoRJDpGYuFqeFkvvXvnsej+SxYS5sSibVt+F6/gpfUTAJl9py1Xh+QUNnABLE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=rx9JGret; arc=none smtp.client-ip=209.85.216.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rx9JGret" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-382ef647e20so1131982a91.1 for ; Wed, 26 Aug 2026 03:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787739845; x=1788344645; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=pw/vnND8u4fIjmZBCSgSJHXI2o3qxjuK90n28G0R7dE=; b=rx9JGretHDZFe2/xVnZUcCEp6tVXzJ+IXT8cI9ihbrjCVpBjkpxoelIZUS+hV/80D0 MZ0eVDXtbH+SBbf8ELHQOq8RoXoGcv5mF8ATi8XnsgGc1clKC8/QJ7GiEOeZA0L2ZbiA +e5ez7UXb1IhZ99nPSuUng9TeGAiEwHlCg/7o/q1xZs8PmGJ/dh+HBeSZY4QQzx7DDcZ Ra/Rseskq9T+3ywjReUw3IjFIjqsIcWTXEWhF3B2n6MQo++OA5Lnqh40EnHgIXKRAl+d bl2LHuOdARZ4+diQQP8QIhEEHzemmwpBrD9LdzHirQUS7X62eTxoyiFUApT6lN53wmwX ikyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787739845; x=1788344645; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=pw/vnND8u4fIjmZBCSgSJHXI2o3qxjuK90n28G0R7dE=; b=p1+Bve2K5stoUGtTFIdECddNmCSyG2WVqLBkxYPBQlWVeXc9iilxbRf8W00o8jRjdC AE3fktn0IehcRGkGDnnlkQxNWl+wzgfugPM/LGgx20fO0vVL5ayZYbB1ihaXFp8RvfCJ r3XM2GQrOApVRFs16n/9mMOR8NOGDLEp0+vTifJSS/7zQ9V1UDEKf+w4OPWi04U+W2Ct QNvaP3U7jiCSaMVCCzMDrifCAeCOpFA7dH6Rw0TojqBPf7QggtNSGkV+qM4JGW/j1Xlo IAHXWlwJn/PQf5YRmzcQjn7tbb9zskns4HmaUfURPJzmoGwTYjqtjGY5HqaLxO+p8hpX 07eg== X-Forwarded-Encrypted: i=1; AHgh+RqOIRk3Yd57aVHW0F0vvoaQRL3q8BQkZJg3EIZAJB8OWCYZpMfojAVgv6zDFXg9XCH+XM4JDRa/5YomvXw=@vger.kernel.org X-Gm-Message-State: AFuF++m2qQkulzimK5v4YLFh617VlizaWTgbr+VmXuyBhHo+ajoq5Ybm hYoxb6hiKhDf4mlRcJ2e9CZQcne8eXe3EYPC+I6yAUVIx3wSDRRytbab X-Gm-Gg: AR+sD1107CK0R3VdG5NuwJB3rJD2H2Kap3qqeFA+H+g+JtwbaBxKzZoa3EXVvb/4KB/ U8dmVItXVUqn6T4NB3vWgBJwviKRw3GXOoxovqxFBb3ebR6fbbIe/GJKtTE6YxMq2b3idopUITC 592QG20aeUHAACaySfaKHIsbotaoOoHjtyojTgS/8Kj6G9B27rXJWwYL0uNmAFrr3P3ivsxpb/t SardNXB/wWaS/zNNF8PusAElSXXsj0O4dLXkkF3kMuRj++d+FbYF6cO3qVVDH2A95O/3sTXT70i 8yans2KESxjPxfvsTyFjBZD64Bz1eHYQa3tv/d1SqUbd1f7w/4ldRKZCTI3iXzpgROuCH8JR/1p ZS8/dYIsuvlTIVNJqx7KRwPNnRo5znpPQs99i17rBxRklq9Mlfu9Ia0aTIS5r1gFzpmx+cUXzRG ni5fdboTO9lNdFovfN7X49jP2Hj10lZGhLLr32aI+6xmSTQkHUqequ2dR4xwR7uPVy X-Received: by 2002:a17:90a:c107:b0:381:a766:efc9 with SMTP id 98e67ed59e1d1-3966d412aa5mr12550916a91.7.1787739844634; Wed, 26 Aug 2026 03:24:04 -0700 (PDT) Received: from celestia ([2402:1980:c23:7fa2:94a9:2164:3642:a5a8]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-141a905c18bsm7535836c88.14.2026.08.26.03.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Aug 2026 03:24:04 -0700 (PDT) From: Liew Rui Yan To: sj@kernel.org Cc: aethernet65535@gmail.com, akpm@linux-foundation.org, damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [RFC PATCH] mm/damon: fix damos quota walk-position tracking Date: Wed, 26 Aug 2026 18:24:13 +0800 Message-ID: <20260826102413.8466-1-aethernet65535@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260825135458.64555-1-sj@kernel.org> References: <20260825135458.64555-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Tue, 25 Aug 2026 06:54:57 -0700 SJ Park wrote: > On Tue, 25 Aug 2026 20:46:16 +0800 Liew Rui Yan wrote: > > > DAMOS uses charge_target_from/charge_addr_from to remember how far a > > quota-limited walk has progressed. The current implementation has two > > problems: > > > > 1. Once set, the cursor unconditionally skips and resets at the last > > region of the tracked target, so the last region can be skipped even > > when it has not been processed. > > I don't fully understand this. Could you please clarify more? Maybe adding a > realistic example scenario would be helpful. > Problem: Unconditional skip of the last region In the current damos_skip_charged_region(), there is this logic: if (r == damon_last_region(t)) { quota->charge_target_from = NULL; quota->charge_addr_from = 0; return true; /* Skip */ } Scenario: 1. Target has 2 regions: R1 (0-100 bytes) and R2 (100-200 bytes). 2. Quota is configured to process only 50 bytes per window. 3. Window 1: Processes R1 (0-50). Quota is full. Cursor is saved at (Target, 50). 4. Window 2: Skips R1 (0-50). Processes R1 (50-100). Quota is full. Cursor is saved at (Target, 100), which is exactly the start of R2. 5. Window 3: The loop reaches R2. Because R2 is damon_last_region(t), the old code unconditionally returns true, skipping R2 entirely and resetting the cursor. Result: R2 is permanently skipped even though it has never been processed. To fix this, the patch advances the cursor every time a region is walked, regardless of whether it is applied or filtered out. This allows DAMON to accurately track whether the last region has already been visited, eliminating the need for the unconditional reset. > > > > 2. The cursor only advances when the quota becomes full. Regions that > > are filtered out do not move the cursor, and the scheme can remain > > stuck on the same regions. > > I don't fully understand this, either. Could you pleae clarify more? > Problem 2 is a false positive. As long as the quota is not full, DAMON will continue iterating to find applicable regions. I mistakenly assumed in the commit message that encountering filtered-out or invalid regions would cause the cursor to stall. This patch ensures that every target is traversed sequentially and deterministically, even when the quota is set very low. I omitted this benefit in the initial problem description. If you think it is okay, I will add it in the next revision. Best regards, Rui Yan