Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757281AbcJXEdY (ORCPT ); Mon, 24 Oct 2016 00:33:24 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:54351 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1757143AbcJXEch (ORCPT ); Mon, 24 Oct 2016 00:32:37 -0400 From: Anshuman Khandual To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: mhocko@suse.com, js1304@gmail.com, vbabka@suse.cz, mgorman@suse.de, minchan@kernel.org, akpm@linux-foundation.org, aneesh.kumar@linux.vnet.ibm.com, bsingharora@gmail.com Subject: [RFC 5/8] mm: Add new flag VM_CDM for coherent device memory Date: Mon, 24 Oct 2016 10:01:54 +0530 X-Mailer: git-send-email 2.1.0 In-Reply-To: <1477283517-2504-1-git-send-email-khandual@linux.vnet.ibm.com> References: <1477283517-2504-1-git-send-email-khandual@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16102404-0020-0000-0000-00000044D12F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16102404-0021-0000-0000-000000C34D89 Message-Id: <1477283517-2504-6-git-send-email-khandual@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-10-23_18:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1610240081 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2569 Lines: 89 VMAs containing coherent device memory should be marked with VM_CDM. These VMAs need to be identified in various core kernel paths and this new flag will help in this regard. Signed-off-by: Anshuman Khandual --- include/linux/mm.h | 5 +++++ mm/mempolicy.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 3a19185..acee4d1 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -182,6 +182,11 @@ extern unsigned int kobjsize(const void *objp); #define VM_ACCOUNT 0x00100000 /* Is a VM accounted object */ #define VM_NORESERVE 0x00200000 /* should the VM suppress accounting */ #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */ + +#ifdef CONFIG_COHERENT_DEVICE +#define VM_CDM 0x00800000 /* Contains coherent device memory */ +#endif + #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */ #define VM_ARCH_2 0x02000000 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */ diff --git a/mm/mempolicy.c b/mm/mempolicy.c index cb1ba01..b983cea 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -174,6 +174,47 @@ static void mpol_relative_nodemask(nodemask_t *ret, const nodemask_t *orig, nodes_onto(*ret, tmp, *rel); } +#ifdef CONFIG_COHERENT_DEVICE +static bool nodemask_contains_cdm(nodemask_t *nodes) +{ + int weight, nid, i; + nodemask_t mask; + + + if (!nodes) + return false; + + mask = *nodes; + weight = nodes_weight(mask); + nid = first_node(mask); + for (i = 0; i < weight; i++) { + if (isolated_cdm_node(nid)) + return true; + nid = next_node(nid, mask); + } + return false; +} + +static void update_coherent_vma_flag(nodemask_t *nmask, + struct page *page, struct vm_area_struct *vma) +{ + if (!page) + return; + + if (nodemask_contains_cdm(nmask)) { + if (!(vma->vm_flags & VM_CDM)) { + if (isolated_cdm_node(page_to_nid(page))) + vma->vm_flags |= VM_CDM; + } + } +} +#else +static void update_coherent_vma_flag(nodemask_t *nmask, + struct page *page, struct vm_area_struct *vma) +{ +} +#endif + static int mpol_new_interleave(struct mempolicy *pol, const nodemask_t *nodes) { if (nodes_empty(*nodes)) @@ -2045,6 +2086,8 @@ alloc_pages_vma(gfp_t gfp, int order, struct vm_area_struct *vma, zl = policy_zonelist(gfp, pol, node); mpol_cond_put(pol); page = __alloc_pages_nodemask(gfp, order, zl, nmask); + update_coherent_vma_flag(nmask, page, vma); + out: if (unlikely(!page && read_mems_allowed_retry(cpuset_mems_cookie))) goto retry_cpuset; -- 2.1.0