remove libdss from Makefile
[GitHub/moto-9609/android_kernel_motorola_exynos9610.git] / mm / swapfile.c
index e47a21e64764507d65b04285971c3b34fb327a07..4f9e522643a2b9a82cb4aac42ca0e75cad3e2c26 100644 (file)
@@ -2218,7 +2218,8 @@ int try_to_unuse(unsigned int type, bool frontswap,
                 */
                if (PageSwapCache(page) &&
                    likely(page_private(page) == entry.val) &&
-                   !page_swapped(page))
+                   (!PageTransCompound(page) ||
+                    !swap_page_trans_huge_swapped(si, entry)))
                        delete_from_swap_cache(compound_head(page));
 
                /*
@@ -2829,8 +2830,9 @@ static struct swap_info_struct *alloc_swap_info(void)
        struct swap_info_struct *p;
        unsigned int type;
        int i;
+       int size = sizeof(*p) + nr_node_ids * sizeof(struct plist_node);
 
-       p = kzalloc(sizeof(*p), GFP_KERNEL);
+       p = kvzalloc(size, GFP_KERNEL);
        if (!p)
                return ERR_PTR(-ENOMEM);
 
@@ -2841,7 +2843,7 @@ static struct swap_info_struct *alloc_swap_info(void)
        }
        if (type >= MAX_SWAPFILES) {
                spin_unlock(&swap_lock);
-               kfree(p);
+               kvfree(p);
                return ERR_PTR(-EPERM);
        }
        if (type >= nr_swapfiles) {
@@ -2855,7 +2857,7 @@ static struct swap_info_struct *alloc_swap_info(void)
                smp_wmb();
                nr_swapfiles++;
        } else {
-               kfree(p);
+               kvfree(p);
                p = swap_info[type];
                /*
                 * Do not memset this entry: a racing procfs swap_next()
@@ -2902,6 +2904,35 @@ static int claim_swapfile(struct swap_info_struct *p, struct inode *inode)
        return 0;
 }
 
+
+/*
+ * Find out how many pages are allowed for a single swap device. There
+ * are two limiting factors:
+ * 1) the number of bits for the swap offset in the swp_entry_t type, and
+ * 2) the number of bits in the swap pte, as defined by the different
+ * architectures.
+ *
+ * In order to find the largest possible bit mask, a swap entry with
+ * swap type 0 and swap offset ~0UL is created, encoded to a swap pte,
+ * decoded to a swp_entry_t again, and finally the swap offset is
+ * extracted.
+ *
+ * This will mask all the bits from the initial ~0UL mask that can't
+ * be encoded in either the swp_entry_t or the architecture definition
+ * of a swap pte.
+ */
+unsigned long generic_max_swapfile_size(void)
+{
+       return swp_offset(pte_to_swp_entry(
+                       swp_entry_to_pte(swp_entry(0, ~0UL)))) + 1;
+}
+
+/* Can be overridden by an architecture for additional checks. */
+__weak unsigned long max_swapfile_size(void)
+{
+       return generic_max_swapfile_size();
+}
+
 static unsigned long read_swap_header(struct swap_info_struct *p,
                                        union swap_header *swap_header,
                                        struct inode *inode)
@@ -2937,23 +2968,12 @@ static unsigned long read_swap_header(struct swap_info_struct *p,
        p->cluster_next = 1;
        p->cluster_nr = 0;
 
-       /*
-        * Find out how many pages are allowed for a single swap
-        * device. There are two limiting factors: 1) the number
-        * of bits for the swap offset in the swp_entry_t type, and
-        * 2) the number of bits in the swap pte as defined by the
-        * different architectures. In order to find the
-        * largest possible bit mask, a swap entry with swap type 0
-        * and swap offset ~0UL is created, encoded to a swap pte,
-        * decoded to a swp_entry_t again, and finally the swap
-        * offset is extracted. This will mask all the bits from
-        * the initial ~0UL mask that can't be encoded in either
-        * the swp_entry_t or the architecture definition of a
-        * swap pte.
-        */
-       maxpages = swp_offset(pte_to_swp_entry(
-                       swp_entry_to_pte(swp_entry(0, ~0UL)))) + 1;
+       maxpages = max_swapfile_size();
        last_page = swap_header->info.last_page;
+       if (!last_page) {
+               pr_warn("Empty swap-file\n");
+               return 0;
+       }
        if (last_page > maxpages) {
                pr_warn("Truncating oversized swap area, only using %luk out of %luk\n",
                        maxpages << (PAGE_SHIFT - 10),