Lines Matching defs:bm
555 static void memory_bm_position_reset(struct memory_bitmap *bm)
557 bm->cur.zone = list_entry(bm->zones.next, struct mem_zone_bm_rtree, list);
558 bm->cur.node = list_entry(bm->cur.zone->leaves.next, struct rtree_node, list);
559 bm->cur.node_pfn = 0;
560 bm->cur.node_bit = 0;
563 static void memory_bm_free(struct memory_bitmap *bm, int clear_nosave_free);
653 static int memory_bm_create(struct memory_bitmap *bm, gfp_t gfp_mask, int safe_needed)
661 INIT_LIST_HEAD(&bm->zones);
677 list_add_tail(&zone->list, &bm->zones);
680 bm->p_list = ca.chain;
681 memory_bm_position_reset(bm);
687 bm->p_list = ca.chain;
688 memory_bm_free(bm, PG_UNSAFE_CLEAR);
695 * @bm: Memory bitmap.
697 static void memory_bm_free(struct memory_bitmap *bm, int clear_nosave_free)
701 list_for_each_entry(zone, &bm->zones, list) free_zone_bm_rtree(zone, clear_nosave_free);
703 free_list_of_pages(bm->p_list, clear_nosave_free);
705 INIT_LIST_HEAD(&bm->zones);
711 * Find the bit in memory bitmap @bm that corresponds to the given PFN.
712 * The cur.zone, cur.block and cur.node_pfn members of @bm are updated.
717 static int memory_bm_find_bit(struct memory_bitmap *bm, unsigned long pfn, void **addr, unsigned int *bit_nr)
723 zone = bm->cur.zone;
732 list_for_each_entry(curr, &bm->zones, list)
755 node = bm->cur.node;
756 if (zone == bm->cur.zone && ((pfn - zone->start_pfn) & ~BM_BLOCK_MASK) == bm->cur.node_pfn) {
774 bm->cur.zone = zone;
775 bm->cur.node = node;
776 bm->cur.node_pfn = (pfn - zone->start_pfn) & ~BM_BLOCK_MASK;
785 static void memory_bm_set_bit(struct memory_bitmap *bm, unsigned long pfn)
791 error = memory_bm_find_bit(bm, pfn, &addr, &bit);
796 static int mem_bm_set_bit_check(struct memory_bitmap *bm, unsigned long pfn)
802 error = memory_bm_find_bit(bm, pfn, &addr, &bit);
810 static void memory_bm_clear_bit(struct memory_bitmap *bm, unsigned long pfn)
816 error = memory_bm_find_bit(bm, pfn, &addr, &bit);
821 static void memory_bm_clear_current(struct memory_bitmap *bm)
825 bit = max(bm->cur.node_bit - 1, 0);
826 clear_bit(bit, bm->cur.node->data);
829 static int memory_bm_test_bit(struct memory_bitmap *bm, unsigned long pfn)
835 error = memory_bm_find_bit(bm, pfn, &addr, &bit);
840 static bool memory_bm_pfn_present(struct memory_bitmap *bm, unsigned long pfn)
845 return !memory_bm_find_bit(bm, pfn, &addr, &bit);
858 static bool rtree_next_node(struct memory_bitmap *bm)
860 if (!list_is_last(&bm->cur.node->list, &bm->cur.zone->leaves)) {
861 bm->cur.node = list_entry(bm->cur.node->list.next, struct rtree_node, list);
862 bm->cur.node_pfn += BM_BITS_PER_BLOCK;
863 bm->cur.node_bit = 0;
869 if (!list_is_last(&bm->cur.zone->list, &bm->zones)) {
870 bm->cur.zone = list_entry(bm->cur.zone->list.next, struct mem_zone_bm_rtree, list);
871 bm->cur.node = list_entry(bm->cur.zone->leaves.next, struct rtree_node, list);
872 bm->cur.node_pfn = 0;
873 bm->cur.node_bit = 0;
883 * @bm: Memory bitmap.
886 * set bit in @bm and returns the PFN represented by it. If no more bits are
892 static unsigned long memory_bm_next_pfn(struct memory_bitmap *bm)
898 pages = bm->cur.zone->end_pfn - bm->cur.zone->start_pfn;
899 bits = min(pages - bm->cur.node_pfn, BM_BITS_PER_BLOCK);
900 bit = find_next_bit(bm->cur.node->data, bits, bm->cur.node_bit);
902 pfn = bm->cur.zone->start_pfn + bm->cur.node_pfn + bit;
903 bm->cur.node_bit = bit + 1;
906 } while (rtree_next_node(bm));
932 static void memory_bm_recycle(struct memory_bitmap *bm)
937 list_for_each_entry(zone, &bm->zones, list) recycle_zone_bm_rtree(zone);
939 p_list = bm->p_list;
1040 * @bm: Memory bitmap.
1042 * Set the bits in @bm that correspond to the page frames the contents of which
1045 static void mark_nosave_pages(struct memory_bitmap *bm)
1068 mem_bm_set_bit_check(bm, pfn);
1168 struct memory_bitmap *bm = free_pages_map;
1176 memory_bm_position_reset(bm);
1177 pfn = memory_bm_next_pfn(bm);
1183 pfn = memory_bm_next_pfn(bm);
1185 memory_bm_position_reset(bm);
1958 static inline unsigned int alloc_highmem_pages(struct memory_bitmap *bm, unsigned int nr_highmem)
1970 memory_bm_set_bit(bm, page_to_pfn(page));
1980 static inline unsigned int alloc_highmem_pages(struct memory_bitmap *bm, unsigned int n)
2118 * @bm: Memory bitmap.
2121 * PFNs corresponding to set bits in @bm are stored in the area of memory
2124 static inline void pack_pfns(unsigned long *buf, struct memory_bitmap *bm)
2129 buf[j] = memory_bm_next_pfn(bm);
2220 static void mark_unsafe_pages(struct memory_bitmap *bm)
2233 duplicate_memory_bitmap(free_pages_map, bm);
2271 * @bm: Memory bitmap.
2275 * corresponding bit in @bm.
2277 static int unpack_orig_pfns(unsigned long *buf, struct memory_bitmap *bm)
2286 if (pfn_valid(buf[j]) && memory_bm_pfn_present(bm, buf[j])) {
2287 memory_bm_set_bit(bm, buf[j]);
2318 * @bm: Memory bitmap.
2320 * The bits in @bm that correspond to image pages are assumed to be set.
2322 static unsigned int count_highmem_image_pages(struct memory_bitmap *bm)
2327 memory_bm_position_reset(bm);
2328 pfn = memory_bm_next_pfn(bm);
2334 pfn = memory_bm_next_pfn(bm);
2345 * @bm: Pointer to an uninitialized memory bitmap structure.
2352 * @bm (it must be unitialized).
2356 static int prepare_highmem_image(struct memory_bitmap *bm, unsigned int *nr_highmem_p)
2360 if (memory_bm_create(bm, GFP_ATOMIC, PG_SAFE)) {
2382 memory_bm_set_bit(bm, page_to_pfn(page));
2389 memory_bm_position_reset(bm);
2390 safe_highmem_bm = bm;
2492 static unsigned int count_highmem_image_pages(struct memory_bitmap *bm)
2497 static inline int prepare_highmem_image(struct memory_bitmap *bm, unsigned int *nr_highmem_p)
2524 * @bm: Memory bitmap with unsafe pages marked.
2526 * Use @bm to mark the pages that will be overwritten in the process of
2536 static int prepare_image(struct memory_bitmap *new_bm, struct memory_bitmap *bm)
2546 nr_highmem = count_highmem_image_pages(bm);
2547 mark_unsafe_pages(bm);
2554 duplicate_memory_bitmap(new_bm, bm);
2555 memory_bm_free(bm, PG_UNSAFE_KEEP);
2557 error = prepare_highmem_image(bm, &nr_highmem);
2614 static void *get_buffer(struct memory_bitmap *bm, struct chain_allocator *ca)
2618 unsigned long pfn = memory_bm_next_pfn(bm);